A Floyd triangle is a right angled triangle consisting of consecutive natural numbers starting with one and then goind down through the rows.
For Example:
Define 5 rows Floys triangle.
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
#include <stdio.h>
int main()
{
int row;
printf("Enter the rows : ");
scanf("%d", &row);
int k=1;
for(int i=1; i<=row; i++){
for(int j=1; j<=i; j++){
printf("%d ", k);
k++;
}
printf("\n");
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int row;
cout<<"Enter the rows : ";
cin>>row;
int k=1;
for(int i=1; i<=row; i++){
for(int j=1; j<=i; j++){
cout<<k<<" ";
k++;
}
cout<<endl;
}
return 0;
}
#include <stdio.h>
int main()
{
int row;
printf("Enter the rows : ");
scanf("%d", &row);
int k=1, i = 1, j=1;
while(i<=row){
j = 1;
while(j<=i){
printf("%d ", k);
k++;
j++;
}
i++;
printf("\n");
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int row;
cout<<"Enter the rows : ";
cin>>row;
int k=1, i = 1, j=1;
while(i<=row){
j = 1;
while(j<=i){
cout<<k<<" ";
k++;
j++;
}
i++;
cout<<endl;
}
return 0;
}
#include <stdio.h>
int main()
{
int row;
printf("Enter the rows : ");
scanf("%d", &row);
for(int i=1; i<=row; i++){
for(int j=1; j<=i; j++){
printf("* ");
}
printf("\n");
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int row;
cout<<"Enter the rows : ";
cin>>row;
for(int i=1; i<=row; i++){
for(int j=1; j<=i; j++){
cout<<"* ";
}
cout<<endl;
}
return 0;
}
Comments
Oops!