Below is a very simple program to find the arithmetic operator.
Please feel free to put a comment if need an explanation.
#include
#include
void main()
{
float a1,a2;
char operator;
printf("\n Enter the values of a1 operator a2\n");
scanf("%f%c%f",&a1,&operator,&a2);
switch(operator)
{
case '+':
printf("%.2f",a1+a2);
break;
case '-':
printf("%.2f",a1-a2);
break;
case '*':
printf("%.2f",a1*a2);
break;
case '/':
if(a2==0)
printf("error\n");
else
printf("%.2f",a1/a2);
break;
default: printf("unknown operatotr\n");
break;
}
}
Comments