Star triangle frame pyramid

Q. Write a C program to print the following star structure
or
Q. Write a C program to print a triangle star frame.

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

Ans.

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

The output of above program would be:

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

Comments