Star pyramid pattern

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

*
***
******

Ans.

/*c program for print the specific star structure*/
#include<stdio.h>
int main()
{
 int n=2,r,c;
 printf("*\n");
 for(r=1; r<=2; r++)
 {
  for(c=1; c<=r*3; c++)
     printf("*");
  printf("\n");
 }
 return 0;
}

The output of above program would be:

Output of star pattern pyramid C program
Figure: Screen-shot for star triangle/pyramid C program

Comments