实验8-1-2 计算两数的和与差(10 分)

实验8-1-2 计算两数的和与差(10 分)

本题要求实现一个计算输入的两数的和与差的简单函数。

函数接口定义:

1
void sum_diff( float op1, float op2, float *psum, float *pdiff );

其中op1op2是输入的两个实数,*psum*pdiff是计算得出的和与差。

裁判测试程序样例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>

void sum_diff( float op1, float op2, float *psum, float *pdiff );

int main()
{
float a, b, sum, diff;

scanf("%f %f", &a, &b);
sum_diff(a, b, &sum, &diff);
printf("The sum is %.2f\nThe diff is %.2f\n", sum, diff);

return 0;
}

/* 你的代码将被嵌在这里 */

输入样例:

1
4 6

输出样例:

1
2
The sum is 10.00
The diff is -2.00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

void sum_diff( float op1, float op2, float *psum, float *pdiff );

int main()
{
float a, b, sum, diff;

scanf("%f %f", &a, &b);
sum_diff(a, b, &sum, &diff);
printf("The sum is %.2f\nThe diff is %.2f\n", sum, diff);

return 0;
}
void sum_diff( float op1, float op2, float *psum, float *pdiff ){
*psum=op1+op2;
*pdiff=op1-op2;
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×