补充:调用函数的实参可以是表达式
return 结束当前函数
exit 结束进程,子函数调用连主函数也结束
#include <stdio.h>
#include <string.h>
int main(void)
{
calc_demo();
return 0;
}
int calc_demo(){
char cmd[5]={0};
int a=0,b=0,i=0;
while(1){
printf("please input method and 2 params:\n");
scanf("%s %d %d",cmd,&a,&b);
//比较字符串,调用方法,获取结果并打印
if(0==strcmp(cmd,"add")){
printf("resule=%d\n",add(a,b));
}else if(0==strcmp(cmd,"sub")){
printf("result=%d\n",sub(a,b));
}else if(0==strcmp(cmd,"mux")){
printf("result=%d\n",mux(a,b));
}else if(0==strcmp(cmd,"dive")){
printf("result=%d\n",dive(a,b));
}
}
return 0;
}
int add(int a,int b){
return a+b;
}
int sub(int a,int b){
return a-b;
}
int mux(int a,int b){
return a*b;
}
int dive(int a,int b){
return a/b;
}