Monday, October 29, 2012

Number Pyramid

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

54321
5432
543
54
5

Ans.

/*c program for number pyramid*/
#include<stdio.h>
int main()
{
 int num,r,c;
 printf("Enter any number: ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
  for(c=num; c>=r; c--)
     printf("%d",c);
  printf("\n");
 }
 return 0;
}

The output of above program would be:

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

No comments:

Post a Comment