是用c语言编写的计算器小程序方面的问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 14:08:12
#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;//如果输入错误,返回-1
for(i=0;corch[i]&&curch!=corch[i];i++);//循环数组corch,从第一元素开始,如果corch[i]不为空且
//输入的字符不等于corch[i],就依次往下,其实就是如果输入的字符是
//corch[]中的,这个循环就停止

if(i<strlen(corch)) break;//如果i<strlen(corch)就是跳出这个while循环,就是说输入的字符是corch[]中的某个字符
}
return curch;//返回值
}//这个函数的作用就是获得你输入的字符并且这个字符在corch[]中
int getid()
{ int i;
if(curch>='0'&&curch<='9')//如果curch在0到9之间
{ for(num=0;curch>='0'&&curch<='9';getach()

#include <stdio.h>//头文件,文件包含标准输入输出流
/*以下为定义的函数声明*/
nt 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
//型指针数组
int num,curch;//定义的INT型全局变量
/*char型数组,并初始化赋值*/
char chtbl[]="+-*/()=";
char corch[]="+-*/()=0123456789";
后面的好像都有注释