Floyd's Triangle - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 26, 2020

Floyd's Triangle

                

Question

To Print Floyd's Triangle using numbers.

Sample TestCaseExpected Output

Enter number of rows : 3                                                                               

                                                                                                                       2 3 

                                                                                                                       4 5 6 

Answer


 #include<bits/stdc++.h>
int main()
{
    int rows,number=1;
    cout<<"Enter no of rows :";
    cin>>rows;
    for(int i=1;i<=rows;i++)
    {
        for(int j=1;j<=i;++j)
        {
            cout<<number<<" ";
            ++number;
        }
        cout<<endl;
    }
    return 0;
}

No comments:

Post a Comment