08 January 2022

Switch case with goto

 #include<stdio.h>

#include<conio.h>


void main()

{

int a, b, no;

clrscr();


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

scanf("%d", &a);


printf("Enter value of b: ");

scanf("%d", &b);


printf("\n1. Addition");

printf("\n2. Subtraction");

printf("\n3. Multiplication");

printf("\n4. Division");

printf("\n5. 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");

}

goto x;

getch();

}

No comments:

Post a Comment