Decreased Number Triangle

Q. Write a C program for decreased number triangle as:

5
54
543
5432
54321

Ans.

/*c program for decreased number triangle*/
#include<stdio.h>
int main()

{
 int num,r,c,n;
 printf("Enter no. of rows : ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
   for(c=1,n=num; c<=r; c++,n--)
       printf("%d",n);
   printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:

Output of Decreased Number Triangle C program
Figure: Screen-shot for Decreased Number Triangle C program



Comments