Tuesday, March 19, 2013

Floyd's Triangle

Floyd's triangle is a right-angled triangular array of natural numbers, used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner:

Program : 

#include<iostream>

using namespace std;

int main()

{

        int n,i,j,a=1;
        cout<<"Enter array size : ";
        cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            cout<<a<<" ";
            a++;
        }
        cout<<endl;
    }
    return 0;

}


Output:

Enter n : 5


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

0 comments:

Post a Comment