求助错误指出?
题目:输入两个实数a,b,然后交换它们的值,最后输出(提示:要交换两个数得借助一个中间变量temp。首先让temp存放a的值,然后把b存入a,再把temp存入b就完成了)#include <stdio.h>
int main()
{
float a,b,temp;
printf("输入a和b:");
temp=0;
scanf("%d,%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("%d,%d\n",a,b);
return 0;
}
最后ab的值总是为0? #include <stdio.h>
int main()
{
float a,b,temp;
printf("enter a and b:");
temp = 0;
scanf("%f,%f",&a,&b);
temp=a;
a=b;
b=temp;
printf("%f,%f\n",a,b);
return 0;
}
数据是float类型啊, 你赋值和打印都是%d整型啊,把所有的%d改成%f #include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
a ^= b;
b ^= a;
a ^= b;
printf("%d %d", a, b);
return 0;
}13 7
7 13
页:
[1]