A program to display the following series:


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

 

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

void main()
{
clrscr();
int i,j,k,n;

cout<<"Enter a number of stars in the middle row: ";
cin>>n;

for(i=1;i<=n;i++)
{
for(j=n-i;j>=1;j--)
cout<<" ";
for(k=1;k<=i;k++)
cout<<"* ";
cout<<"\n";
}

for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
cout<<" ";
for(k=i;k>=1;k--)
cout<<"* ";
cout<<"\n";
}

getch();
}

 

< Back