Floyd’s triangle in C++.

Floyd’s triangle : Floyd’s triangle is a right angled-triangle which formed by the natural numbers, so the following C++ program ask to the user to enter the range (up to how many line he or she wants to print) to print the Floyd’s Triangle up to the given range:

 

 

Let’s Open turboC++ and write the following Code.

 

//Code

 

#include<conio.h>

#include<iostream.h>

void main()

{

long int n,i,c,a=1;

clrscr();

cout<<”enter range:”;

cin>>n;

cout<<”Floyd’s triangle is :\n “;

for(i=1;i<=n;i++)

{

for(c=1;c<=i;c++,a++)

{

cout<<””<<a;

}

cout<<”\n”;

}

getch();

}

 

 

Step 2 : Run the program and see output.

 

 

Output.

 

output

 

Happy coding.

 

 

Tags: , , ,