Number Pyramid

Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

 5
 45
 345
 2345
 12345

Ans.

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


The output of above program would be:


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

Comments