4.18.2013

Simple Star Pyramid

Q. Write a C program to print the following star structure as:

*********
*******
*****
***
*

Ans.

/*c program for simple star pyramid*/
#include<stdio.h>
int main()
{
 int num=5,n=9,r,c;
 for(r=1; r<=num; r++,n=n-2)
 {
   for(c=1; c<=n; c++)
       printf("*");
   printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:

Output of simple star pyramid C program
Figure: Screen shot for simple star pyramid C program

No comments:

Post a Comment