A nested loop means a loop inside another loop. In this program, the outer for loop controls the number of rows, while the inner for loop prints the numbers from 1 to 5 in each row. The process is repeated until all 5 rows are displayed.
How It Works?
r and c.
for loop starts with r = 1 and runs until r <= 5.
for loop starts with c = 1 and runs until c <= 5.
c followed by a space.
#include <stdio.h> #include <conio.h> main() { int r, c; clrscr(); for(r = 1; r <= 5; r++) { for(c = 1; c <= 5; c++) { printf("%d ", c); } printf("\n"); } getch(); }
for loops to print the numbers from 1 to 3 in 3 rows.for loops to print a number pattern using rows and columns.r and c. Run both loops from 1 to 3. Print c inside the inner loop and print a new line after each row.#include <stdio.h> #include <conio.h> main() { int r, c; clrscr(); for(r = 1; r <= 3; r++) { for(c = 1; c <= 3; c++) { printf("%d ", c); } printf("\n"); } getch(); }
for loops. The outer loop controls the rows, while the inner loop prints the numbers from 1 to 3 in each row. After completing one row, a new line is printed, and the process repeats until all three rows are displayed.