Program to print series from 10 to 1 using nested loops
What Are Nested Loops?
In C programming, nested loops refer to using one loop inside another loop. The inner loop runs completely for each iteration of the outer loop.
for (int i = 1; i <= n; i++) { // Outer loop
for (int j = 1; j <= m; j++) { // Inner loop
// code to execute
}
}
Nested loops are commonly used for:
-
Printing patterns
-
Traversing matrices or grids
-
Repeating a task multiple times in a structured way
C Program to Print Series from 10 to 1 Using Nested Loops
Let’s now use nested loops to print numbers from 10 to 1, and repeat that series multiple times.
#include <stdio.h> int main() { int i, j; for (i = 1; i <= 3; i++) { // Outer loop: runs 3 times for (j = 10; j >= 1; j--) { // Inner loop: prints 10 to 1 printf("%d ", j); } printf("\n"); // Move to next line after each row } return 0; }
OUTPUT 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1
Explanation:
-
Outer Loop (
for (i = 1; i <= 3; i++)
):-
This loop controls how many times the series from 10 to 1 is printed.
-
Runs 3 times to create 3 rows.
-
-
Inner Loop (
for (j = 10; j >= 1; j--)
):-
This prints numbers from 10 down to 1.
-
Runs every time the outer loop runs.
-
-
printf("\n");
:-
Moves the output to a new line after each row.
-
Summary
-
Nested loops run in a layered structure: the inner loop completes fully before the outer loop moves to its next iteration.
-
This technique is useful for grid printing, pattern problems, and number sequences.
-
You can adjust loop conditions to print different shapes, tables, or logic-based outputs.