The following program will show how to make a pyramid using C and C++. The number of rows of the pyramid will be taken from the user and then it will be stored into a variable. Also two while loops are being used to build the pyramid.
C and C++ pyramid program
#include<stdio.h>
#include<conio.h>
void main()
{
int i = 0, j , n ;
clrscr();
printf("How many rows in pyramid:");
scanf("%d",&n);
while(i<n)
{
j=0;
while(j<=i)
{
gotoxy(30+j,10+i);
printf("%d",j);
printf("%d",j);
j++;
}
j=0;
while(j<=i)
while(j<=i)
{
gotoxy(30-j,10+i);
printf("%d",j);
j++;
j++;
}
i++;
printf("\n");
}
getch();
}
Output
Output
