08 January 2022

Switch Case with do..while()

 #include<stdio.h>

#include<conio.h>


void main()

{

int a, b, no;

clrscr();

do

{

printf("\n\nEnter value of a: ");

scanf("%d", &a);


printf("Enter value of b: ");

scanf("%d", &b);


printf("\n\n------------");

printf("\n    Menu    \n");

printf("------------");

printf("\n||1. Addition");

printf("\n||2. Subtraction");

printf("\n||3. Multiplication");

printf("\n||4. Division");

printf("\n||5. Exit");

printf("\n\nEnter Your Choice: ");

scanf("%d", &no);


switch(no)

{

case 1: printf("\n Sum = %d", a+b);

break;


case 2: printf("\n Sub = %d", a-b);

break;


case 3: printf("\n Mul = %d", a*b);

break;


case 4: printf("\n Div = %d", a/b);

break;


case 5: exit(0);


default: printf("\nEnter valid choice");

}

}while(no != 5);

getch();

}

No comments:

Post a Comment