Sunday, 2 December 2012

Star Triangle Pyramid

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

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

Ans.

/*c program for star pyramid design*/
#include<stdio.h>
int main()
{

 int n=9,r,c;
 for(r=5; r>=1; r--,n=n-2)
 {
   for(c=1; c<=n; c++)
      printf("*");
   printf("\n");
 }
 return 0;
}

The output of above program would be:


Output of star triangle C program
Figure: Screen shot for star triangle C program


No comments:

Post a Comment