codescracker


c++

C++ Program to Print Floyd Triangle



« Previous Program Next Program »


Print Floyd's Triangle in C++

To print Floyd's Triangle in C++ programming, you have to ask from the user to enter the number of line (or row, upto which he/she want to print Floyd's Triangle). Now to print Floyd's Triangle, use two for loops, the outer for loop is responsible for rows and the inner for loop is responsible for columns. Now print Floyd's triangle on the output screen as shown here in the following program.

C++ Programming Code to Print Floyd's Triangle

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

Following is the simple Floyd's Triangle :

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

Following C++ program illustrates it:

/* C++ Program - Print Floyd's Triangle */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int range, i, j, k=1;
	cout<<"Enter the range (upto how many line ?) : ";
	cin>>range;
	cout<<"\nFloyd's Triangle :\n";
	for(i=1; i<=range; i++)
	{
		for(j=1; j<=i; j++, k++)
		{
			cout<<k<<" ";
		}
		cout<<"\n";
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program print floyd triangle

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test