C Program to Demonstrate use of Do While Loop
Write C Program to Demonstrate use of Do While Loop
//Write C Program to Demonstrate use of Do While Loop #include <stdio.h> #include <stdlib.h> int main() { int n; do { printf("\n\n1. Hello World"); printf("\n2. Welcome to the world of programming"); printf("\n3. Exit"); printf("\n\nEnter Your Choice :--> "); scanf("%d",&n); int temp = n; switch(temp) { case 1: printf("\nHello World"); break; case 2: printf("\nWelcome to the world of programming"); break; case 3: exit(0); default: printf("\nPlease enter the valid number"); } }while(n>0); return 0; }
Output:
1. Hello World
2. Welcome to the world of programming
3. Exit
Enter Your Choice :--> 5
Please enter the valid number
1. Hello World
2. Welcome to the world of programming
3. Exit
Enter Your Choice :--> 2
Welcome to the world of programming
1. Hello World
2. Welcome to the world of programming
3. Exit
Enter Your Choice :--> 3