Program Code
Program Code
h>
int main()
{
int a,b,result=0;
char op;
printf("Enter the operator\n");
scanf("%c",&op);
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
if(op=='+')
{
result=a+b;
}
else if(op=='-')
{
result=a-b;
}
else if(op=='*')
{
result=a*b;
}
else if(op=='/')
{
if(b==0)
{
printf("divide by zero error\n");
return 1;
}
else
{
result=a/b;
}
}
else if(op=='%')
{
if(b==0)
{
printf("divide by zero error\n");
return 1;
}
else
{
result=a%b;
}
}
else
{
printf("invalid operator\n");
return 1;
}
printf("Result is %d%c%d=%d",a,op,b,result);
return 0;
}
SAMPLE OUTPUT: