http://www.pudn.com/downloads252/sourcecode/embed/detail1166489.html
#include <stdio.h>#include <stdlib.h>
#include <string.h>
int test(const char *str)
{
int length, i = 0, j = 0
char *pl, *pr, *tmp, sign = 0
tmp = str
length = strlen(str)
for(i = 0 i < length i++){
char c = *(str+i)
搏培 if(c == '+'|| c == '-' || c == '*' || c == '/' || c == '%'){
sign = c
break
}
}
*(tmp + i) = '\0'
pl = tmp
pr = tmp+i+1
i = atoi(pl)
j = atoi(pr)
if(sign == '+')
衫念return i+j
else if(sign == '-')
return i-j
else if(sign == '*')
return i*j
基塌唯 else if(sign == '/')
return i/j
else
return i%j
}
int main(void)
{
char str[10] = {0}
scanf("%s", &str)
printf("%d\n",test(str))
return 0
}
简单写了点,很多容错没做,空格,字母什么的都没有判断,不过简单思路就这样,用解释型语言写简单点,python就很好写
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)