开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
问题(Question):
输入5个浮点数找出最大质
程式码(Code):
#include<stdio.h>
double maximum(double a, double b, double c, double d, double e);
int main(void)
{
double number1 = 0;
double number2 = 0;
double number3 = 0;
double number4 = 0;
double number5 = 0;
printf("%s", "请输入五个小数: \n");
scanf("%1f %1f %1f %1f %1f", &number1, &number2, &number3, &number4,&number5);
printf("最大值为:%1f\n", maximum(number1, number2, number3, number4,number5));
system("pause");
return 0;
}
double maximum(double a, double b, double c, double d, double e)
{
double max = a;
if (b>max)
{
max = b;
}
if (c>max)
{
max = c;
}
if (d>max)
{
max = d;
}
if (e>max)
{
max = e;
}
return max;
}
补充说明(Supplement):
1.我输入整数时没问题,输入小数只让我输入一次
2.不管输入多少(整数)都无法比较,只会输出0.000000
但是把全部double型态改成float型态却能正常比较(整数)
且输出正确值
3. http://pastebin.com/A9W72kas 这是课本的答案
把小于改大于就是我要的答案(求最大值),输入小数
也没问题,可是我看不出它的程式和我打的差在哪里
恳求哪位大大肯帮我解惑 ORZ....