Floyd’s Triangle is a triangular arrangement of natural numbers, where numbers increase sequentially from 1 row by row. The first row has 1 number, the second row has 2 numbers, the third row has 3 numbers, and so on. This program demonstrates how to print Floyd’s Triangle using nested loops in C.
Understanding The Problem
The program should take the number of rows as input and print numbers sequentially to form Floyd’s Triangle. Each row contains an increasing number of elements, and the numbers continue sequentially across rows. Nested loops are essential to control the rows and numbers per row.
Steps to Solve the Problem:
- Take input for the number of rows from the user.
- Initialize a counter starting from 1.
- Use an outer loop to iterate through each row.
- Use an inner loop to print numbers in the current row and increment the counter.
- Move to a new line after each row.
Solution: Using Nested Loops
Nested loops allow printing numbers sequentially row by row.
#include <stdio.h>
int main() {
int rows, counter = 1;
printf("Enter number of rows: ");
scanf("%d", &rows);
for(int i = 1; i <= rows; i++) {
for(int j = 1; j <= i; j++) {
printf("%-2d ", counter);
counter++;
}
printf("\n");
}
return 0;
}
In this program, the outer loop controls the number of rows. The inner loop prints numbers in each row and increments the counter so that numbers continue sequentially. After each row, a newline is printed to create the triangular structure of Floyd’s Triangle.

FAQs
Q1: Can we start Floyd’s Triangle from a number other than 1?
Yes, you can initialize the counter with any number to start the triangle from that number.
Q2: Can the triangle be inverted?
Yes, by adjusting the loop logic, you can print an inverted Floyd’s Triangle, though it is less common.
Q3: Can this handle large numbers of rows?
Yes, but for very large numbers, the output may become wide and hard to read. Using proper formatting can help.
Conclusion
This program demonstrates how to print Floyd’s Triangle using nested loops. By carefully controlling rows and incrementing numbers sequentially, you can create a simple, structured triangular number pattern. The logic can be extended to create other triangular patterns or number-based designs.
References & Additional Resources
- C Programming Tutorial – Beginner-friendly tutorials covering loops, nested loops, and number patterns in C.
- GeeksforGeeks – Floyd’s Triangle – Explanation and examples of Floyd’s Triangle in C.
- TutorialsPoint – C Loops – Explanation of nested loops for printing patterns in C.