Write a program to print the number from 1 to 10 using 'While Loop' :-
//To print the numbers from 1 to 10
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
while(i<=10)
{
printf("%d",i);
i=i+1;
printf("\n");
getch();
}
}
Output:
1
2
3
4
5
6
7
8
9
10
To print the numbers from 1 to 10
1. We will declare a variable for loop counter (number).
2. We will check the condition whether loop counter is less than or equal to 10, if condition is true numbers will be printed.
3. If condition is false – loop will be terminated.