開發平台(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....