#include <stdio.h>
int main() {
int rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (int i = 1; i <= rows; i++) {
int current = 1;
for (int j = 1; j <= i; j++) {
printf("%d ", current);
current++;
}
printf("\n");
}
return 0;
}
Enter the number of rows: 6
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
rows
to store the number of rows in the triangle.printf
and scanf
.for
loops to print the triangle. The outer loop controls the number of rows in the triangle, and the inner loop controls the number of numbers to be printed in each row.printf
and then increment current
to print the next number in the next iteration of the loop.printf
to move to the next row of the triangle.return
0 to indicate successful execution of the program.