Pages

Showing posts with label how to make a pyramid with C program. Show all posts
Showing posts with label how to make a pyramid with C program. Show all posts

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