4.04.2013

Number star pyramid

Q. write a C program to print the following number star pyramid as:

1
**
123
****
12345
******

Ans.

/* c program for number star pyramid */
#include<stdio.h>
int main()
{
 int num=6,r,c;

 for(r=1; r<=num; r++)
 {
   for(c=1; c<=r; c++)
   {
      if(r%2==0)
         printf("*");
      else
         printf("%d",c);
   }
   printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:


Output of number star pyramid C program
Figure: Screen shot for number-star pyramid C program

No comments:

Post a Comment