To print Floyd's triangle in C programming, use two for loops, the outer for loop is responsible for rows and the inner for loop is responsible for columns to print Floyd's triangle. Following is the simple Floyd's Triangle :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Since Floyd’s triangle is a right angled-triangle using 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 the Floyd's triangle) to print the Floyd's Triangle upto the given range:
/* C Program - Print Floyd's Triangle */ #include<stdio.h> #include<conio.h> void main() { clrscr(); int range, i, j, k=1; printf("Enter the range (upto how many line ?) : "); scanf("%d",&range); printf("\nFloyd's Triangle :\n"); for(i=1; i<=range; i++) { for(j=1; j<=i; j++, k++) { printf("%d ",k); } printf("\n"); } getch(); }
When the above c program is compile and executed, it will produce the following result:
You may also like same program in other programming languages: