Jun 13, 2020

C program to print number till it is less than 5 using do-while loop

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.





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:

#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:


Share This:    Facebook Twitter

0 comments:

Post a Comment

If you have any doubts, please discuss here...