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
3 comments:
How can I do it in for loop.... in C programming language.
Thanks for sharing such a nice idea, piece of writing is nice,
thats why i have read it entirely
Also visit my blog post: fan facebook français ()
sir please give me the code for
1
1 3
1 3 5
1 3 5 7
1 3 5
1 3
1
Post a Comment