There are number of ways to display and Floyd triangle display consecutive numbers in different row. In this example, you will write a program to print Floyd triangle.

Problem Definition

The program ask for number of row to print. When the user input the number, a list of consecutive numbers are printed for each row. The number of elements for each row also grows.

Suppose the user input is \Large 5 , then five rows of consecutive number are printed and each row has one more number than the previous. See the figure below.

Figure 1 - Floyd Triangle with consecutive number in different rows
Figure 1 – Floyd Triangle

Program Codes – Floyd Triangle

#include <stdio.h>

int main()
{
    int n, i, c, a = 1;

    printf("Enter the Number of Rows for Floyd Triangle:\n");
    scanf("%d", &n);

    for (i = 1; i <= n; i++)
    {
        for (c = 1; c <= i; c++)
        {
            printf("%d\t", a);
            a++;
        }
        printf("\n");
    }

    return 0;
}
#include <iostream>
using namespace std;

int main()
{
    int n, a = 1;

    cout << "Enter the Number of Rows for Floyd Triangle:\n";
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        for (int c = 1; c <= i; c++)
        {
            cout << a << "\t";
            a++;
        }
        cout << endl;
    }

    return 0;
}

Output

Enter the Number of Rows for Floyd Triangle:
5

1
2       3
4       5       6
7       8       9       10
11      12      13      14       15