Q. Write a C program to floyd algorithm number triangle in C as:
2 3
4 5 6
7 8 9 10
Ans.
/* c program for floyd algorithm number triangle */
#include<stdio.h>
int main()
{
int r,c,n,x=1;
printf("Enter No. Of rows : ");
scanf("%d", &n);
for(r=1; r<=n; r++)
{
for(c=1; c<=r; c++,x++)
printf(" %d",x);
printf("\n");
}
getch();
return 0;
}
/*************************************************************
The output of above program would be:
**************************************************************/
![]() |
| Figure: Screen shot for Floyd algorithm number triangle C program |
A
B C
D E F
G H I J
9
8 7
6 5 4
3 2 1 0
1
2 3
4 5 6
7 8 9 10
4 5 6
2 3
1
