> 其他 >
实现交换两个变量值的操作.例如:若变量a中的值原为8,b中的值为3;程序运行
后a中的值为3,b中的值为8.请改正函数fun 中的错误,使它能得到正确的结果.注
意:不要改动main函数,不得增行或删行,也不得更改程序的结构
#include
int fun(int x,int y)
int t;
t=x;x=y;y=t;
main()
int a,b;
a=8;b=3;
fun(&a,&b);
printf("%d,%d",a,b);
人气:248 ℃ 时间:2020-06-20 14:52:31
解答
在你的程序中,函数后面的“{ }”不能丢,但你的两个函数都丢掉了“{ }”;下面是你要的程序:
#include
int fun(int *x,int *y)
{
\x05int t;
\x05t=*x;*x=*y;*y=t;
}
main()
{
int a,b;
a=8;b=3;
fun(&a,&b);
printf("%d,%d",a,b);
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版