Floyd's Triangle
C
Easy
8 views
Problem Description
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15 Consecutive numbers. Maintain the counter and continuously increase it.
Official Solution
#include <stdio.h>
int main() {
int rows = 5; // Number of rows in the triangle
int num = 1; // Counter to keep track of consecutive numbers
for (int i = 1; i <= rows; i++) { // Loop for rows
for (int j = 1; j <= i; j++) { // Loop for columns in each row
printf("%d ", num);
num++; // Increase counter
}
printf("n"); // Move to next row
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!