用C语言编一个简单的计算器小程序

来源:百度知道 编辑:UC知道 时间:2024/05/10 22:59:30

你说的是 vc 还是 tc 啊???
其他的运算:
#include <stdio.h>
int add(int x,int y) {return x+y;}
int sub(int x,int y) {return x-y;}
int mul(int x,int y) {return x*y;}
int div(int x,int y) {return x/y;}
int (*func[])()={add,sub,mul,div};
int num,curch;
char chtbl[]="+-*/()=";
char corch[]="+-*/()=0123456789";
int getach() {
int i;
while(1) {
curch=getchar();
if(curch==EOF) return -1;
for(i=0;corch[i]&&curch!=corch[i];i++);
if(i<strlen(corch)) break;
}
return curch;
}

int getid() {
int i;
if(curch>='0'&&curch<='9') {
for(num=0;curch>='0'&&curch<='9';getach()) num=10*num+curch-'0';
return -1;
}
else {
for(i=0;chtbl[i];i++) if(chtbl[i]==curch) break;
if(i<=5)