In this article, we are going to learn about how to print Floyd’s triangle pattern in C language.
Desired Output for 7 rows:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
C Program to Print Floyd’s Triangle
In this example, we are going to print Floyd’s Triangle Pattern,
#include<stdio.h>
int main()
{
int size, num=1;
printf("Please enter the size for Floyd Triangle: ");
scanf("%d",&size);
for(int row=1; row<= size; row++)
{
for(int col = 1; col <= row; col++)
printf("%5d",num++);
printf("\n");
}
return 0;
}
Output
Please enter the size for Floyd Triangle: 9
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45