conformation!!!

is this acorrect way to show the display of(using for loops)
a
aa
aaa
aaaa


#include<iostream>
using namespace std;
void main()
{ int j;


{for(j=0;j<1;j++)
cout<<"a\n";}

{ for(j=0;j<2;j++)
cout<<"a";
cout<<endl;}

{ for(j=0;j<3;j++)
cout<<"a";
cout<<endl;}

{ for(j=0;j<4;j++)
cout<<"a";
cout<<endl;}

system("pause");}
make nested loops something like:
1
2
3
4
5
for (int i=1;i<=4;i++) {
   for (int j=1;j<=i;j++) cout<<"a";
   cout<<endl;
}
What you did would work fine, but below code would be more clean and flexible

1
2
3
4
5
6
7
int lines = 3 ;
for(int i = 0 ; i < lines ; i++)
{
    for( int j= 0 ; j <= i ; j++)
      std::cout << a ;
  std::cout << std::endl;
}
Last edited on
Topic archived. No new replies allowed.