C++ Program to display Floyd’s Triangle.




In this example we will see how to print Floyd’s Triangle using C++.

1
2 3
3 4 5
4 5 6 7
5 6 7 8 9
6 7 8 9 10 11
#include <iostream>
using namespace std;
int main()
{
  int rows,i,j,k=0;
  cout<<"Enter number of rows: ";
  cin>>rows;
  for(i=1;i<=rows;i++)
  {
    for(j=1;j<=i;++j)
      cout<<k+j<<" ";
    ++k;
    cout<<endl;
  }
  return 0;
}

/*
OUTPUT
Enter number of rows: 6
1
2 3
3 4 5
4 5 6 7
5 6 7 8 9
6 7 8 9 10 11

*/

 

After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax

  • if it finds errors, it lists them
  • If there are no errors, it translates the C++ program into a program in machine language which you can execute

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*