| Previous | Home | Next |
/** Example of Switch Case in C **/
#include<stdio.h>
#include <conio.h>
main()
{
int menu, num1, num2, total;
clrscr();
printf ("enter any two numbers ");
scanf ("%d %d", &num1, &num2 );
printf ("enter your choice\n");
printf("1=addition\n");
printf("2=subtraction\n");
printf("3=multiplication\n");
scanf ("%d", &menu );
switch( menu )
{
case 1: total = num1 + num2; break;
case 2: total = num1 - num2; break;
case 3: total = num1* num; break;
default: printf ("Invalid option selected\n");
}
if( menu == 1 )
printf ("%d plus %d is %d\n", numb1, numb2, total );
else if( menu == 2 )
printf ("%d minus %d is %d\n", num1, num2, total );
else (menu==3)
printf ("%d cross %d is %d\n", num1, num2, total );
}
enter any two number
45 40
1=addition
2=subtraction
3=multiplication
enter your choice
2
minus is 5
| Previous | Home | Next |