c - 查找最大数 (C) - 代码无效

标签 c

我需要用户输入三个数字,然后我的程序才能显示这些数字中最大的一个。我似乎无法弄清楚问题所在。我得到的结果是 "最大的数是 0.000"

#include <stdio.h>

int main()
{

double n1, n2, n3;

printf("Enter your three numbers: ");
scanf("%1f %1f, %1f", &n1, &n2, &n3);

if (n1>= n2 && n1>= n3)
    printf("The greatest number is %f", n1);

if (n2>=n1 && n2>= n3)
    printf("The greatest number is %f", n2);

if (n3>=n2 && n3>=n1)
    printf("The greatest number is %f", n3);


return 0;
}

最佳答案

编译器知道!

$ gcc -Wall temp.c
temp.c:9:23: warning: format specifies type 'float *' but the argument has type 'double *' [-Wformat]
scanf("%1f %1f, %1f", &n1, &n2, &n3);
       ~~~            ^~~
       %1lf
temp.c:9:28: warning: format specifies type 'float *' but the argument has type 'double *' [-Wformat]
scanf("%1f %1f, %1f", &n1, &n2, &n3);
           ~~~             ^~~
           %1lf
temp.c:9:33: warning: format specifies type 'float *' but the argument has type 'double *' [-Wformat]
scanf("%1f %1f, %1f", &n1, &n2, &n3);
                ~~~             ^~~
                %1lf
3 warnings generated.

关于c - 查找最大数 (C) - 代码无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53482342/

相关文章:

c++ - OpenGL:如何更新矩形纹理的子图像?

c - (x || !x) 什么时候为假?

C程序: help about variable definition sequence

c - 我如何摆脱最后一个逗号?

c - 测试两个 __m128i 变量之间的相等性

c - Maple 代码生成 : How to declare variables automatically?

c - strtok 和 valgrind 泄漏 c

android - 为什么 openSL 在使用麦克风时不报告??? (安卓4.4)

c - 如何将新创建的用户线程,Linux 64 的上下文执行保存到 C 中的结构?

java - 重建 Android Studio 项目时出现错误