单点时限: 1.0 sec
内存限制: 256 MB
定义函数 SD,计算两个数的和及两个数的差。
//********** Specification of SD **********
void SD(int a, int b, int *p);
/* PreCondition: a,b,a+b,a-b是在 [-100,100] 范围内的整数
PostCondition: p所指的整数值是a+b, p+1所指的整数值是a-b
*/
只需按要求写出函数定义,并使用给定的测试程序测试你所定义函数的正确性。
不要改动测试程序。测试正确后,将测试程序和函数定义一起提交。
#include <stdio.h>
//********** Specification of SD **********
void SD(int a, int b, int *p) {
}
/***************************************************************/
int main() {
int a, b, p[2];
scanf("%d%d", &a, &b);
SD(a, b, p);
printf("%d %d\n", p[0], p[1]);
return 0;
}
样例
input
8 5
output
13 3
input
-5 -6
output
-11 1
#include <stdio.h>
//********** Specification of SD **********
void SD(int a, int b, int *p) {
*p = a+b;
*(p+1) = a-b;
return;
}
int main() {
int a, b, p[2];
scanf("%d%d", &a, &b);
SD(a, b, p);
printf("%d %d\n", p[0], p[1]);
return 0;
}
该文章描述了一个C语言编程任务,要求定义一个名为SD的函数,该函数接收两个在[-100,100]范围内的整数a和b,然后将它们的和存储在p指向的位置,差存储在p+1的位置。提供的测试程序用于验证函数的正确性。
1万+

被折叠的 条评论
为什么被折叠?



