实现交换两个变量值的操作.例如:若变量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);
}
推荐
猜你喜欢
- 同学们,新年到了,你想在新年到来之际跟父母说些什么呢?
- 六年级数学书上册练习十六第8题怎么做
- 运动场跑道400米,小红跑步的速度是爷爷的5/3倍,爷爷的速度为120米/秒,小红的速度为200米/秒.他们从同一起点沿跑道的同一方向同时出发,5分钟后小红第一次追上了爷爷.如果小红追上爷爷后立即转身沿相反方向跑,几分钟后小红又一次与爷爷相
- 设A(a,1),B(2,b),c(4,5)为坐标平面上三点,O为坐标原点,若OA在OC方向上的射影与OB在OC方向上的投影相同
- Now I have to wash my schoolbag.翻译成中文
- 设函数f(x)=ex-e-x (Ⅰ)证明:f(x)的导数f′(x)≥2; (Ⅱ)若对所有x≥0都有f(x)≥ax,求a的取值范围.
- 按原始人类出现时间的顺序,下列排列正确的是
- 根据蝗虫的生长发育过程,防止蝗虫的最佳时期为什么是若虫阶段?