8.27.2013

C Star Triangle

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

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

Ans.

/*c program for star triangle design*/
#include<stdio.h>
int main()
{
 int r,c,n;
 printf("*\n");

 for(r=1; r<=4; r++)
 {
  if(r<=3)
  {
    for(c=1; c<=2; c++)
        printf("*");
  }
  else
  {
    for(c=1; c<=6; c++)
        printf("*");
  }
  printf("\n");
 }
 getch();
 return 0;
}

/*************************************************************
The output of above program would be:
**************************************************************/


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

No comments:

Post a Comment