Skip to main content

Featured

functions in Python

C program to print pyramid of asterisks

//C++ program to print pyramid of asterisks
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k,l,sp1=4,sp2=-1;
for(i=1;i<=5;i++,sp1--,sp2=sp2+2)
{
for(j=1;j<=sp1;j++)
{
cout<<" ";
}
if(i==1)
{
cout<<"*";
}
if(i==2||i==3||i==4)
{
cout<<"*";
for(k=1;k<=sp2;k++)
{
cout<<" ";
}
cout<<"*";
}
if(i==5)
{
for(l=1;l<=9;l++)
{
cout<<"*";
}
}
 cout<<"\n";
}
getch();
}


The output:

Comments

Popular Posts