我需要用户输入三个数字,并且我的程序必须显示这些数字中的最大数字。我似乎无法找出问题所在。我得到的结果是 “最大数量是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;
}
答案 0 :(得分:5)
编译器知道!
$ 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.
答案 1 :(得分:2)
正如Vorsprung所述,您需要一种正确的格式来读取/显示,所以:
#include <stdio.h>
int main()
{
double n1, n2, n3;
printf("Enter your three numbers: ");
scanf("%lf %lf, %lf", &n1, &n2, &n3);
if (n1>= n2 && n1>= n3)
printf("The greatest number is %lf", n1);
if (n2>=n1 && n2>= n3)
printf("The greatest number is %lf", n2);
if (n3>=n2 && n3>=n1)
printf("The greatest number is %lf", n3);
return 0;
}