C++ : generate the following figure


            *
 ***
*****
       *******
  *****
  ***
  *

==================================================


#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
static int a=1;
for(int i=1;i<=4;i++)
{
for(int j=0;j<=4-i;j++)
{
cout<<" ";
}
for(int k=1;k<=a;k++)
{
cout<<"*";
}
a=a+2;
cout<<endl;
}


for(int i=3;i>=1;i--)
{
for(int j=1;j<=5-i;j++)
{
cout<<" ";
}

a-=2;
  for(int k=1;k<=a-2;k++)
{
cout<<"*";
}

cout<<endl;
}
getch();
return(0);
}

No comments:

Post a Comment