Star triple pyramid

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

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

Ans.

Star pyramid program make 3 module program
Screen shot of solutions for star pyramid
breaks in module sub programs


/*c program for star pyramid or star triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,n=4;
 for(r=1;r<=2; r++)
 {
  for(sp=1; sp<=n; sp++)
    printf(" ");
  for(c=1; c<=r; c++)
  {
    printf("*");
    printf(" ");
  }
  printf("\n");
  n=n-1;
 }

 for(r=1;r<=3; r++)
 {
  for(sp=0; sp<=n+1; sp++)
    printf(" ");
  for(c=1; c<=r; c++)
  {
    printf("*");
    printf(" ");
  }
  printf("\n");
  n=n-1;
 }

 for(r=1;r<=4; r++)
 {
  for(sp=0; sp<=n+4; sp++)
    printf(" ");
  for(c=1; c<=r; c++)
  {
    printf("*");
    printf(" ");
  }
  printf("\n");
  n=n-1;
 }
 getch();
 return 0;
}

The output of above program would be:

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


Comments