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




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


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



No comments:

Post a Comment

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