How to Print Floyd's Triangle Using C++ Programming Language

Floyd's Triangle:
It is right angled triangular array of natural  numbers.Rows are filled with consecutive numbers starting with one like that
1
2 3
4 5 6
7 8 9 10
....
It applications are in computer science.
To start programming practice, this is basic task assigned to students.Let start to have a look on program code.



Program code:

# include <iostream>
# include <conio.h>
using namespace std;

int main()
{

   int x, y, z, r;

 
   cout << " Enter No. Of Rows =  ";
   cin >>  r ;
   cout<< endl ;
   cout<< "Floyd triangle is given below " << endl << endl ;

   y  =  1;

   for ( x = 0; x < r; x++ )
   {
       for ( z = 0; z <= x; z++ )
       {
              cout << y << "  ";
              y++;
       }
       cout << endl;
   }
   getch();
}


Output:




Hope that you will find this helpful.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.