In: Computer Science
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2 #####1 ####12 ###123 ##1234 #12345
Pattern 1:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int count=1; //initializing count as 1
for(int i=1;i<=4;i++){ //numbers of rows
for(int j=1;j<=5;j++){ //number of columns
cout<<count; //printing digits in row
count=count+2; //adding 2
}
cout<<endl; //go to new line
count=1; //make count again 1 for 2nd row
}
}
Pattern 2:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int count=1; //initializing count as 1
for(int i=1;i<=5;i++){ //for loop for row
for(int j=1;j<=6;j++){ //for loop for column
if(j<=6-i){
cout<<"#";
}
else
{
cout<<count++;
}
}
cout<<endl;
count=1;
}
}