Jun 14, 2020

C program using do-while loop to check inside or outside the loop

Ex: : write a C program to check program is inside or outside the loop. How to write a C program to check program is inside or outside the loop.  C program to check program is inside or outside the loop. 


This program shows the working of do-while loop.




Step by step logic of the given program:

1. First declare intiger variable i=0.

2. After that inside the do-while loop accept input from user.

3. Give condition while(i!=1) that means the loop will iterate until 1 is entered.





Program:

#include<stdio.h>
int main()
{
int i=0;

do
{
printf("\nYou are inside the loop");
printf("\nPress 1 to exit from loop: ");
scanf("%d",&i);
}while(i!=1);

printf("\nYou are out of do-while loop");

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...