Learn about Reverse Floyd’s triangle in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Reverse Floyd’s triangle in C
The below program prints the Reverse Floyd’s triangle in the C programming. Look the various outputs while changing the number of rows.
Program:
#include<stdio.h>
int main()
{
int n, i, j;
printf("Enter number of rows: ");
scanf("%d",&n);
int k = n*(n+1)/2;
for(i=n; i>=0; i--)
{
for(j=1; j<=i; j++)
printf("%-5d",k--);
printf("\n");
}
return 0;
}
Output:
Enter number of rows: 5 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Output 2:
Enter number of rows: 6 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Floyd’s triangle in C using recursion
C Program For Floyd’s Triangle