/*
* For example:
* input : 3*2 then press "Enter"
* output: 13 * 25 = ?
* 13 * 25 = 325
*/
#include <stdio.h>
#include <math.h>
#define ERROR -1
int main(void)
{
char ch;
int a,b,num;
scanf("%d %c %d",&a,&ch,&b);
printf("%d %c %d = ?\n",a,ch,b);
num = ((ch=='*')?(a*b):((ch=='/')?(a/b):((ch=='+')?(a+b):((ch=='-')?(a-b):((ch=='^')?(int)pow(a,b):ERROR)))));
if(num==-1)
{
printf("Operation symbol error!\n");
return -1;
}
else
printf("%d %c %d = %d\n",a,ch,b,num);
return 0;
}
运行结果如下:
无聊之作,不喜勿喷!