Switch statement program
#include<stdio.h>
main()
{
int a,b,c,ch=1;
clrscr();
printf("enter a,b values\n:");
scanf(%d%d",&a,&b);
printf("[1]addition\n");
printf("[2]subtraction\n");
printf("[3]multiplication\n");
printf("[4]division\n");
printf("[5]exit");
printf("enter your choice\n");
scanf("%d",&ch);
if(ch<=5)
{
switch(ch)
{
case 1:
c=a+b;
printf("c=%d",c);
break;
case 2:
c=a-b;
printf("c=%d",c);
break;
case 3:
c=a*b;
printf("c=%d",c);
break;
case 4:
c=a/b;
printf("c=%d",c);
break;
case 5:
exit;
}
}
else
printf("not valid");
getch();
}
output1 :-
enter a,b values: 4 7
[1]addition
[2]subtraction
[3]multiplication
[4]division
[5]exit
enter your choice 1
c = 11
output2 :-
enter a,b values: 41 97
[1]addition
[2]subtraction
[3]multiplication
[4]division
[5]exit
enter your choice 22
not valid
0 comments:
Post a Comment