7-3 程序填空:指针变量作函数参数
fun函数通过指针参数返回两个整数的和、差,主函数调用fun函数求整数x、y的和、差。
输入样例:
44,55
输出样例:
44 + 55 = 99
44 - 55 = -11
已有代码:
请在每对“/**/”之间填写内容。
include [HTML_REMOVED]
void fun(int x, int y, int p, int q)
{
// // = x + y;
// // = x - y;
}
int main()
{
int x, y, sum, dif;
scanf(“%d,%d”, &x, &y);
fun(x, y, // //, // //);
printf(“%d + %d = %d\n”, x, y, sum);
printf(“%d - %d = %d\n”, x, y, dif);
return 0;
}
正确解答
include [HTML_REMOVED]
void fun(int x, int y, int p, int q)
{
p = x + y;
q = x - y;
}
int main()
{
int x, y, sum, dif;
scanf(“%d,%d”, &x, &y);
fun(x, y,&sum,&dif);
printf(“%d + %d = %d\n”, x, y, sum);
printf(“%d - %d = %d\n”, x, y, dif);
return 0;
}
错误解答
include [HTML_REMOVED]
void fun(int x, int y, int p, int q)
{
p = x + y;
q = x - y;
}
int main()
{
int x, y, sum, dif;
scanf(“%d,%d”, &x, &y);
fun(x, y,sum,dif);
printf(“%d + %d = %d\n”, x, y, sum);
printf(“%d - %d = %d\n”, x, y, dif);
return 0;
}