coderz.py

Keep Coding Keep Cheering!

Floyd’s Triangle

Accessing Elements

Floyd’s triangle is a triangular array of natural numbers and it is named after Robert Floyd, a renowned computer scientist popularly known for the design of the Floyd–Warshall algorithm.

Program code:

#include <iostream>
using namespace std;

int main()
{
    int rows, num = 1;

    cout << "Enter number of rows: ";
    cin >> rows;

    for(int i = 1; i <= rows; i++)
    {
        for(int j = 1; j <= i; ++j)
        {
            cout << num << " ";
            ++num;
        }

        cout << endl;
    }

    return 0;
}
Output:
Enter number of rows: 6
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21

Note: also read about Pascals triangle.

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Comment

Your email address will not be published. Required fields are marked *

Advertisement