C語言指針問題 這程序怎么錯了
# include<stdio.h>
void exchange(int *a,int*b)
{
int t;
t = *a;
*a = *b;
*b = t;
return;
}
int main(void)
{
int a,b;
printf("請輸入兩個整數(shù)
");
scanf("%a %b",&a,&b);
exchange(&a,&b);
printf("a=%d,b=%d
",a,b);
return 0;
}
wuye11****** 2013-05-04 01:29:12
你犯了嚴重的錯誤
main函數(shù)中的
scanf(“%a %b)啥意思啊...........你讀英文字母啦,,,,應(yīng)該是scanf(%d%d).....
# include<stdio.h>
void exchange(int *a,int*b)
{
int t;
t = *a;
*a = *b;
*b = t;
}
int main( )
{
int a,b;
printf("請輸入兩個整數(shù)
");
scanf("%d %d",&a,&b);
exchange(&a,&b);
printf("a=%d,b=%d ",a,b);
return 0;
}
低級錯誤不能犯啊。
lclyx1****** 2014-07-31 10:23:15 1 樓