Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2 #####1 ####12 ###123 ##1234 #12345
language c++
Pattern 1
#include <iostream>
using namespace std;
int main()
{
int k=1;
for(int i=1;i<=4;i++){
for(int j=1;j<=5;j++){
cout<<k;
k+=2;
}
cout<<endl;
k=1;
}
return 0;
}
output ->
13579
13579
13579
13579
pattern 2
#include <iostream>
using namespace std;
int main()
{
int k=1;
for(int i=1;i<=5;i++){
for(int j=1;j<=6;j++){
if(j<=6-i){
cout<<"#";
}
else
{
cout<<k++;
}
}
cout<<endl;
k=1;
}
return 0;
}
output->
#####1
####12
###123
##1234
#12345
Get Answers For Free
Most questions answered within 1 hours.