C++ Program To Print Reverse Floyd's Triangle
Floydâs triangle is a triangle with first natural numbers. Task is to print reverse of Floydâs triangle.
Examples:
Input: 4 Output: 10 9 8 7 6 5 4 3 2 1 Input: 5 Output: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
// C++ program to print reverse
// of Floyd's triangle
#include <bits/stdc++.h>
using namespace std;
void printReverseFloyd(int n)
{
int curr_val = n * (n + 1) / 2;
for (int i = n; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
cout << setprecision(2);
cout << curr_val-- << " ";
}
cout << endl;
}
}
// Driver's Code
int main()
{
int n = 7;
printReverseFloyd(n);
return 0;
}
28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1