Ex: write a C program to print number if it is less than or equal to 5 using do while loop. How to write a C program to print number if it is less than or equal to 5 using do while loop. C program to print number if it is less than or equal to 5 using do while loop.
Note:
do-while loop runs at least one even if the condition is false because the condition is evaluated, after the execution of the body of loop.
1. First declare intiger variable i=1.
2. After that inside the do while print value of i.
3. Increment value of i.
Give condition while(i<=5).
#include<stdio.h>
int main()
{
int i=1;
do
{
printf("%d\n",i);
i++;
}while(i<=5);
return 0;
}
Above prgram shows the following output:
Note:
do-while loop runs at least one even if the condition is false because the condition is evaluated, after the execution of the body of loop.
Step by step logic of the given program:
1. First declare intiger variable i=1.
2. After that inside the do while print value of i.
3. Increment value of i.
Give condition while(i<=5).
Program to print numbers till 5 using do-while loop:
#include<stdio.h>
int main()
{
int i=1;
do
{
printf("%d\n",i);
i++;
}while(i<=5);
return 0;
}
Above prgram shows the following output:
No comments:
Post a Comment
If you have any doubts, please discuss here...👇