C语言,设计一个函数,实现加,减,乘,除运算。
设计一个程序,可以模仿计算机完成加,减,乘,除四则运算:由键盘输入两个数,按用户的选择进行一种运算,并给出结果。其中加,减,乘,除各由一个函数实现。...
设计一个程序,可以模仿计算机完成加,减,乘,除四则运算:由键盘输入两个数,按用户的选择进行一种运算,并给出结果。其中加,减,乘,除各由一个函数实现。
展开
展开全部
# include<stdio.h>
double jia(double x, double d)
{
double s;
s = x+d;
return s;
}
double jian(double x, double d)
{
double s;
s = x-d;
return s;
}
double cheng(double x, double d)
{
double s;
s = x*d;
return s;
}
double chu(double x, double d)
{
double s;
s = x/d;
return s;
}
int main(void)
{
double i, j, k;
char t;
k = 0;
printf("请输入要计算什么运算“+”“-”“*”“/”\n");
scanf("%c", &t);
if(t == '+')
{
printf("请输入要相加的两个数\n");
scanf("%lf %lf", &i, &j);
k = jia(i, j);
printf("这两个数相加为%6.2lf\n", k);
}
else if(t == '-')
{
printf("请输入要相减的两个数\n");
scanf("%lf %lf", &i, &j);
k = jian(i, j);
printf("这两个数相减为%6.2lf\n", k);
}
else if(t == '*')
{
printf("请输入要相*的两个数\n");
scanf("%lf %lf", &i, &j);
k = cheng(i, j);
printf("这两个数相*为%6.2lf\n", k);
}
else if(t == '/')
{
printf("请输入要相/的两个数\n");
scanf("%lf %lf", &i, &j);
k = chu(i, j);
printf("这两个数相/为%6.2lf\n", k);
}
else
{
printf("对不起目前只支持“+”“-”“*”“/”\n");
}
return 0;
}
double jia(double x, double d)
{
double s;
s = x+d;
return s;
}
double jian(double x, double d)
{
double s;
s = x-d;
return s;
}
double cheng(double x, double d)
{
double s;
s = x*d;
return s;
}
double chu(double x, double d)
{
double s;
s = x/d;
return s;
}
int main(void)
{
double i, j, k;
char t;
k = 0;
printf("请输入要计算什么运算“+”“-”“*”“/”\n");
scanf("%c", &t);
if(t == '+')
{
printf("请输入要相加的两个数\n");
scanf("%lf %lf", &i, &j);
k = jia(i, j);
printf("这两个数相加为%6.2lf\n", k);
}
else if(t == '-')
{
printf("请输入要相减的两个数\n");
scanf("%lf %lf", &i, &j);
k = jian(i, j);
printf("这两个数相减为%6.2lf\n", k);
}
else if(t == '*')
{
printf("请输入要相*的两个数\n");
scanf("%lf %lf", &i, &j);
k = cheng(i, j);
printf("这两个数相*为%6.2lf\n", k);
}
else if(t == '/')
{
printf("请输入要相/的两个数\n");
scanf("%lf %lf", &i, &j);
k = chu(i, j);
printf("这两个数相/为%6.2lf\n", k);
}
else
{
printf("对不起目前只支持“+”“-”“*”“/”\n");
}
return 0;
}
展开全部
#include<stdio.h>
int s=0;
void jia(folat a,folat b)
{s=a+b;}
void jian(folat a,folat b)
{s=a-b;}
void chen(folat a,folat b)
{s=a*b;}
void chu(folat a,folat b)
{s=a/b;}
void main()
{
folat a,b;
char c;
printf("请输入要计算的式子,如(7+8):");
scanf("%d%c%d",&a,&c,&b,);
switch('c')
{
case '+':jia(a,b)
case '-':jian(a,b)
case '*':chen(a,b)
case '/':chu(a,b)
}
printf("%.2f",s);
}
int s=0;
void jia(folat a,folat b)
{s=a+b;}
void jian(folat a,folat b)
{s=a-b;}
void chen(folat a,folat b)
{s=a*b;}
void chu(folat a,folat b)
{s=a/b;}
void main()
{
folat a,b;
char c;
printf("请输入要计算的式子,如(7+8):");
scanf("%d%c%d",&a,&c,&b,);
switch('c')
{
case '+':jia(a,b)
case '-':jian(a,b)
case '*':chen(a,b)
case '/':chu(a,b)
}
printf("%.2f",s);
}
追问
一编译,好多错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询