《C语言程序设计》江宝钏主编-习题8-2-指针参数传递多个返回值

*题目描述
编写函数,其功能是对传送过来的两个浮点数求出和值与差值,并通过形参传回调用函数。
注意:此题用C语言完成时,必须使用指针方法处理,只提交头文件和
void compute(float a,float b,float *c,float *d)
函数,系统将自动附加下面的main函数后运行,请复制下面的main函数用于调试函数。
其他语言的答案无此要求。
int main(){
float a,b,c,d;
scanf("%f%f",&a,&b);
compute(a,b,&c,&d);
printf("%g %g",c,d);

}
输入
两个浮点数a,b
输出
a+b a-b 用%g输出
样例输入 Copy
1.5 2.5
样例输出 Copy
4 -1*
代码如下:

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
void compute(float a,float b,float *c,float *d)
{
    *c=a+b;
    *d=a-b;
}
int main()
{
    float a, b, c, d;
    scanf("%f%f", &a, &b);
    compute(a, b, &c, &d);
    printf("%g %g", c, d);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值