Friday, 27 April 2012

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



A bottom up Pyramid with odd numbered stars in every row. The number of stars in the last row are 2*number of rows-1.

* * * * * * * * * 
  * * * * * * * 
    * * * * *
      * * *
        *
int main()
{
int c,i,n,space;
printf("Enter the number of rows you want on the Pyramid\n");
scanf("%d",&n);
clrscr();
space=1;
for(i=n;i>=1;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