Ex: write a C program to print number while is less than 10. How to write a C program to print number while is less than 10. C program to print number while is less than 10.
Step by step logic of the given program:
1. First we declare intiger variable no=5.
2. After that use one while loop to check number is less than 10 or not.
3. If number is less than 10 we print no inside the while loop.
4. After that we increment number by 1 (no++).
5. It will print (5 6 7 8 9 10) .
C program to print number while is less than 10:
#include<stdio.h>
int main()
{
int no=5;
while(no<=10)
{
printf("%d ",no);
no++;
}
return 0;
}
Above prgram shows the following output:
Step by step logic of the given program:
1. First we declare intiger variable no=5.
2. After that use one while loop to check number is less than 10 or not.
3. If number is less than 10 we print no inside the while loop.
4. After that we increment number by 1 (no++).
5. It will print (5 6 7 8 9 10) .
C program to print number while is less than 10:
#include<stdio.h>
int main()
{
int no=5;
while(no<=10)
{
printf("%d ",no);
no++;
}
return 0;
}
Above prgram shows the following output: