In this tutorial, we will write Floyd’s triangle pattern program in C. Before that, you should have knowledge on the following topic in C.
Floyd’s Triangle in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h> void main() { int i, j, k = 1, rows; printf("Enter the no. of rows: "); scanf("%d", &rows); printf("Floyd's Triangle:\n"); for (i = 1; i <= rows; i++) { for (j = 1; j <= i; j++, k++) { printf("%2d ", k); } printf("\n"); } getch(); } |
Output: