xxxxxxxxxx
include<stdio.h>
int main()
{
char ch;
int num1,num2;
printf("Choose the operator(+,-,*,/,%%): ");
scanf("%c",&ch);
printf("Enter two numbers: ");
scanf("%d %d",&num1,&num2);
switch(ch)
{
case '+':
printf("%d + %d =\t%d\n",num1,num2,num1+num2);
break;
case '-':
printf("%d - %d =\t%d\n",num1,num2,num1-num2);
break;
case '*':
printf("%d * %d =\t%d\n",num1,num2,num1*num2);
break;
case '/':
printf("%d / %d =\t%d\n",num1,num2,num1/num2);
break;
case '%':
printf("%d %% %d =\t%d\n",num1,num2,num1%num2);
break;
default:
printf("Error! Invalid Operator.");
}
return 0;
}
xxxxxxxxxx
#include<stdio.h>
#include<conio.h>
void main()
{
char choice;
int a,b,res=0;
clrscr();
printf("Enter First value: ");
scanf("%d",&a);
printf("\n Enter Operator: ");
choice=getch();
printf("\n Enter Second value: ");
scanf("%d",&b);
switch(choice)
{
case '+':
res=a+b;
printf("Sum: %d",res);
break;
case '-':
res=a-b;
printf("Difference: %d",res);
break;
case '*':
res=a*b;
printf("Product: %d",res);
break;
case '/':
res=a/b;
printf("Quotient: %d",res);
break;
default:
printf("Enter Valid Operator!!");
}
getch();
}