In this tutorial, we will learn how to write floyd’s triangle program in C.
But before moving on writing program lets know
What is Floyd’s Triangle?
Floyd’s triangle is a right angled triangle, which is made using natural numbers. It is named after Rober Floyd.
Its element is left aligned in which it started filling the rows starting with 1 and then filling with consecutive numbers.
#include<stdio.h>
#include<conio.h>
void main(){
int i,j,k=1,n;
printf("enter the value of n:");
scanf("%d",&n);
for(i = 1; i <= n; i++) {
for(j = 1;j <= i; j++)
printf("%4d", k++);
printf("\n");
}
getch();
}
Output
enter the value of n:5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15