Open In App

C++ Program To Print Reverse Floyd’s Triangle

Last Updated : 17 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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++




// 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;
}


Output: 

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads