For loop
for loop is consist of 3 expression, first = initialize, second = check whether the condition, third = change index value (increase/ decrease). If we need to use more than one condition in same for loop then send condition will determine the first one, adding that we can also use a relational operator. Let's see the given example below.
syntax
for(initialization; condition; increment/ decrease)
{
statement(s);
}
Structure
QUESTION:- print first nth natural number by using for loop.
#include <stdio.h>
#include <conio.h>
void main()
{
int no;
printf("enter a value: ");
scanf("%d", &no);
for (int i = 1; i <= no; i++)
printf("%d ", i);
getch();
}
OUTPUT
enter a value:
10
1 2 3 4 5 6 7 8 9 10
0 Comments