Sunday, April 21, 2013

Differ Symbol Pyramid

Q. write C program to print the following symbol pyramid as:

*
$$
***
$$$$

Ans.

/*c program for symbol 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++)
   {
     if(r%2==0)
        printf(" $");
     else
        printf(" *");
   }
   printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:


Output of differ symbol pyramid C program
Figure: Screen shot for differ-symbol pyramid C program

No comments:

Post a Comment