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");}
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