Pages

Thursday, July 14, 2011

Making Pyramid with C and C++ Program

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);
               j++;
             }
             j=0;
             while(j<=i)
             {
                gotoxy(30-j,10+i); 
                printf("%d",j);
               j++;
             }
             i++;
             printf("\n");
   }

   getch();
}

Output



3 comments:

Unknown said...

How can I do it in for loop.... in C programming language.

Anonymous said...

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 ()

Anonymous said...

sir please give me the code for

1
1 3
1 3 5
1 3 5 7
1 3 5
1 3
1