4.01.2013

Star sequence pyramid

Q. Write a C program to print the following symbol (star) pyramid.

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

Ans.

/*c program for star pyramid*/
#include<stdio.h>
int main()
{
 int num,r,c;
 printf("Enter no. of rows: ");
 scanf("%d"&num);
 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:

Enter no. of rows: 6
*
**
***
****
*****
******

No comments:

Post a Comment