Wednesday, 17 April 2013

Reverse Number Pyramid

Q. Write a C program to print the reverse number pyramid as:

10 9 8 7
6  5 4
3  2
1

Ans.

/*c program for reverse number pyramid*/
#include<stdio.h>
int main()
{
 int n=4,num,r,c;
 static int p=10;
 num = n;
 for(r=1; r<=n; r++,num--)
 {
   for(c=1; c<=num; c++)
   {
     printf("%d ",p);
     p--;
   }
   printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:

Output for reverse number pyramid C program
Figure: Screen shot for number pyramid C program

No comments:

Post a Comment