#include<stdio.h>
#include<stdlib.h>
main(){
int b,c,r,d;
char a;
while(1){
printf("Enter the operator\n");
scanf("%c",&a);
if(a=='+') d=1;
if(a=='-') d=2;
if(a=='&') d=3;
if(a=='|') d=4;
if(a=='.') d=5;
printf("Enter the operands\n");
scanf("%d",&b);
scanf("%d",&c);
switch(d){
case 1:r=c+b;
break;
case 2:r=c-b;
break;
case 3:r=c&b;
break;
case 4:r=c|b;
break;
case 5:exit(0);
deafult:printf("Enter a valid operator");
}
printf("Result = %d\n",r);
}
}
Выход:
Enter the operator
+
Enter the operands
8
7
Result = 15
Enter the operator
Enter the operands