c语言 定义结构体类型,分别编写函数实现复数的加、减运算,在主函数中调用这些函数进行计算并输出计算结
#include stdio.h
成都创新互联长期为千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为湖南企业提供专业的做网站、网站制作,湖南网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。
struct complex
{
int re;
int im;
};
void add(struct complex a, struct complex b, struct complex *c)
{
c-re=a.re+b.re;
c-im=a.im+b.im;
}
void minus(struct complex a, struct complex b, struct complex *c)
{
c-re=a.re-b.re;
c-im=a.im-b.im;
}
int main()
{
struct complex x,y,s,p;
scanf("%d%d",x.re,x.im);
scanf("%d%d",y.re,y.im);
add(x,y,s);
printf(" sum=%5d+%5di\n",s.re,s.im);
minus(x,y,p);
printf(" product=%5d+%5di\n",p.re,p.im);
return 0;
}
C语言编写5个函数加减乘除取余运算
#includestdio.h
double jia(double a,double b){
return a+b;}
double jian(double a,double b){
return a-b;}
double cheng(double a,double b){
return a*b;}
double chu(double a,double b){
return a/b;}
int modd(int a,int b){
return a%b;}
int main(){
double a,b;
printf("输入两个数字\n");
scanf("%lf%lf",a,b);
printf("加 %lf\n减 %lf\n乘 %lf\n除 %lf\n取模 %d\n",jia(a,b),jian(a,b),cheng(a,b),chu(a,b),modd((int)a,(int)b));
return 0;}
C语言,设计一个函数,实现加,减,乘,除运算。
# includestdio.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;
}
分享文章:c语言写减函数吗 c语言减法函数是哪个符号
网站网址:http://lswzjz.com/article/dojchde.html