gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:22:46 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com