- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
In the program below, we print Floyd’s triangle in C++
Source Code: Print Floyd’s triangle
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
/* 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();
}
Output
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15