c语言计算器改成有参类型
求助如何改成有参数类型#include<stdio.h>
#include <math.h>
int num1;
int num2;
int n;
void input0(){
printf("\n\n***高级简易计算器***\n");
printf("++++++++++++++++++++++++++++++\n");
printf("+ 1.加法 +\n");
printf("+ 2.减法 +\n");
printf("+ 3.乘法 +\n");
printf("+ 4.除法 +\n");
printf("+ 5.求余 +\n");
printf("+ 6.累加 +\n");
printf("+ 7.阶乘 +\n");
printf("+ 8.结束 +\n");
printf("++++++++++++++++++++++++++++++\n");
printf("请选择你的运算类型(1,2,3,4,5,6,7,8)?\n");
}
int input1(){
printf("请输入num1和num2:");
printf("\nnum1=");
scanf("%d",&num1);
printf("num2=");
scanf("%d",&num2);
}
int add(){
input1();
printf("%d+%d=%d",num1,num2,num1+num2);
}
int sub(){
input1();
printf("%d-%d=%d",num1,num2,num1-num2);
}
int multi(){
input1();
printf("%d*%d=%d",num1,num2,num1*num2);
}
float diff(){
input1();
if(num2==0)
printf("除数不可以为0!");
else
printf("%d/%d=%d",num1,num2,num1/num2);
}
int text_1(){
input1();
if(num2==0)
printf("求余数不可以为0!");
else
printf("%d %% %d=%d",num1,num2,num1%num2);
}
int text_2(int n){
int sum,times;
sum=0,times=1;
printf("请输入n:");
scanf("%d",&n);
while(times<=n){
sum+=times;
times++;
}
printf("1+...+%d=%d",n,sum);
}
int text_3(int n){
int mutli,times;
mutli=1,times=1;
printf("请输入n:");
scanf("%d",&n);
if(n>0){
while(times<=n){
mutli*=times;
times++;}
printf("%d!=%d",n,mutli);}
else
printf("请输入正整数!");
}
int main()
{
char in;
printf("\n***高级简易计算器***\n");
printf("++++++++++++++++++++++++++++++\n");
printf("+ 1.加法 +\n");
printf("+ 2.减法 +\n");
printf("+ 3.乘法 +\n");
printf("+ 4.除法 +\n");
printf("+ 5.求余 +\n");
printf("+ 6.累加 +\n");
printf("+ 7.阶乘 +\n");
printf("+ 8.结束 +\n");
printf("++++++++++++++++++++++++++++++\n");
printf("请选择你的运算类型(1,2,3,4,5,6,7,8)?\n");
while(in!='8'){
scanf("%c",&in);
switch(in){
case '1' :add(),input0();break;
case '2' :sub(),input0();break;
case '3' :multi(),input0();break;
case '4' :diff(),input0();break;
case '5' :text_1(),input0();break;
case '6' :text_2(n),input0();break;
case '7' :text_3(n),input0();break;}
}
if(in=='8')
printf("Please enter any key to continue");
return 0;
}
?听不懂 永恒的蓝色梦想 发表于 2020-12-13 19:24
?听不懂
就是改写成有参数有返回值类型的计算器
coletaplock 发表于 2020-12-13 19:48
就是改写成有参数有返回值类型的计算器
听不懂 你不说清楚需求怎么知道啊,比如需要哪些参数,需要哪些输出
页:
[1]