Wednesday, 17 April 2013

Star Pyramid

Q. print the following star structure as:

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

Ans.

/*c star pyramid program*/
#include<stdio.h>
int main()
{
 int num,n,r,c,z;
 printf("Enter no. of rows : ");
 scanf("%d", &num);
 n=num;
 for(r=1; r<num; r++,n--)
 {
  for(c=1; c<=n; c++)
     printf("*");
  printf("\n");
 }
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=r; c++)
      printf("*");
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:

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

No comments:

Post a Comment