C初级问题
来源:百度知道 编辑:UC知道 时间:2024/05/22 15:08:57
#include <stdio.h>
void main()
{
int n,m,temp;
printf("input two no");
scanf("%d,%d",&n,&m);
if(n<m)
{
temp=n;
n=m;
m=temp;
}
printf("the most gongyueshu %d\n",n);
printf("the most gongbeishu %d\n",m);
}
为什么结果m,n没有互换啊?
比如输入n,m 5 56
m结果是个-853364640的数。。。我写错了吗?
void main()
{
int n,m,temp;
printf("input two no");
scanf("%d,%d",&n,&m);
if(n<m)
{
temp=n;
n=m;
m=temp;
}
printf("the most gongyueshu %d\n",n);
printf("the most gongbeishu %d\n",m);
}
为什么结果m,n没有互换啊?
比如输入n,m 5 56
m结果是个-853364640的数。。。我写错了吗?
if(n<m)...n比m小的时候我测试是换了
将scanf("%d,%d",&n,&m); 改为scanf("%d %d",&n,&m); 就可以了
多了个逗号所以出错
当你输入的n<m的时候互换
不满足这个条件时不互换
因为你输入的n > m 了吧..
那是由于 你输入的值不满足你的IF()语句的判断条件!你将输入的改为第一个小于第二个就行!如3,5