Featured
- Get link
- X
- Other Apps
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:
#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:
- Get link
- X
- Other Apps
Labels:
C program to print pyramid
c program to print star pyramid
C++ program to print pyramid of asterisks
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment