|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 jpan1221 于 2020-11-15 17:17 编辑
代码如下:
- include <stdio.h>
- int main() {
- int a, b, c;
- printf("input the first integer number: ");
- scanf("%d", &a);
- getchar();
- printf("input the second integer number: ");
- scanf("%d", &b);
- getchar();
- printf("input the third integer number: ");
- scanf("%d", &c);
- getchar();
- int temp[256] = {0}; int t = 0;
- temp[0] = a; temp[1] = b; temp[2] = c;
- for(int i = 0; i < 3; i++)
- {
- for(int j = i + 1; j < 3; j ++)
- {
- if(temp[i] < temp[j])
- {
- t = temp[i];
- temp[i] = temp[j];
- temp[j] = t;
- }
- }
- }
- printf("The biggest number is:%d\n",temp[0]);
- printf("The smallest number is:%d\n",temp[2]);
- }
复制代码
我没看出来哪里有问题
但是运行结果是这样的:
input the first integer number:10
input the second integer number:1000
input the third integer number:15
The biggest number is:1
000
The smallest number is:0
Process finished with exit code 0
求大佬帮忙看看问题所在
1、三个数比较大小,用不着弄得这么复杂;2、输入的都是整数,用不着用 getchar(); 来吸收回车键;
- include <stdio.h>
- int main() {
- int a, b, c,t,max,min;
- printf("input the first integer number: ");
- scanf("%d", &a);
- printf("input the second integer number: ");
- scanf("%d", &b);
- printf("input the third integer number: ");
- scanf("%d", &c);
-
- max = a;
- min = a;
- if (max < b)
- {
- max = b;
- }
- else
- {
- min = b;
- }
- if (max < c)
- {
- max = c;
- }
- else
- {
- min = c;
- }
- printf("The biggest number is:%d\n",max);
- printf("The smallest number is:%d\n",min);
- }
复制代码
|
|