Friday, 27 April 2012

Printing a Pyramid in C ( A variant with odd number of stars in every row ) - Top Down



A top down Pyramid of odd numbered stars in every row. Makes nice geometry, I guess!

         *
    * * *
  * * * * *
* * * * * * * 
* * * * * * * * *
#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<=2*i-1;c++)
{
printf("* ");
}
printf("\n");
}
getch();
return 0;
}

No comments:

Post a Comment