Friday, 27 April 2012

Printing a Pyramid in C - Top Down



To print something like this: A pyramid is what they call it!

    *
   * *
  * * * 
 * * * *
* * * * *
#include<stdio.h>
#include<conio.h>

int main()
{
int c,i,n,space;
printf("Enter the number of rows you want on the Pyramid\n");
scanf("%d",&n);
clrscr();
space=n;
for(i=1;i<=n;i++)
{
for(c=1;c<=space;c++)
{
printf("  ");
}
space--;
for(c=1;c<=i;c++)
{
printf("* ");
}
printf("\n");
}
getch();
return 0;
}

No comments:

Post a Comment