The for loop is used when the number of iterations is known in advance. In this program, the loop starts from 1 and continues up to 10. During each iteration, the current value of the variable k is displayed on the screen.
Definition:
This program uses a for loop to print the numbers from 1 to 10. The loop executes 10 times and displays one number during each iteration.
How It Works?
k.k with 1 in the for loop.k <= 10.k.k by 1 using k++.Syntax:
for(k = 1; k <= 10; k++)
{
printf("%d", k);
}
#include <stdio.h> #include <conio.h> main() { int k; clrscr(); for(k = 1; k <= 10; k++) { printf("\n %d", k); } getch(); }
for loop to print the numbers from 1 to 20.for loop to display a sequence of numbers by changing the loop condition.k with 1. Use the loop condition k <= 20 and increase the value of k by 1 after each iteration.#include <stdio.h> #include <conio.h> main() { int k; clrscr(); for(k = 1; k <= 20; k++) { printf("\n %d", k); } getch(); }
for loop to print the numbers from 1 to 20. The loop starts with k = 1, continues while k <= 20, and increments k by 1 after each iteration.