#include <stdio.h>
void main() // 改成 int main ()
{
int score, max, min, average, sum, i = 1;
scanf("%d\n", &score); // 如果這時候輸入是 -1 呢
sum = max = min = score;
while (score != -1) { // 這種應該用 do while
scanf("%d", &score);
i++;
if (score > max)
max = score;
if (score < min)
min = score;
sum += score;
}
average = sum / i; // 平均分最好不要用 int
printf("%d%d%d%d", max, min, average, sum);
我修改了一下
int main()
int score, max, min, sum, i;
double average;
printf("請輸入分數\n");
if (score == -1) return 0;
i = 0;
sum = 0;
max = min = score;
do {
} while(score != -1);
average = (double)sum / (double)i;
printf("%d, %d, %f, %d\n", max, min, average, sum);
#include <stdio.h>
void main() // 改成 int main ()
{
int score, max, min, average, sum, i = 1;
scanf("%d\n", &score); // 如果這時候輸入是 -1 呢
sum = max = min = score;
while (score != -1) { // 這種應該用 do while
scanf("%d", &score);
i++;
if (score > max)
max = score;
if (score < min)
min = score;
sum += score;
}
average = sum / i; // 平均分最好不要用 int
printf("%d%d%d%d", max, min, average, sum);
}
我修改了一下
#include <stdio.h>
int main()
{
int score, max, min, sum, i;
double average;
printf("請輸入分數\n");
scanf("%d", &score);
if (score == -1) return 0;
i = 0;
sum = 0;
max = min = score;
do {
i++;
if (score > max)
max = score;
if (score < min)
min = score;
sum += score;
scanf("%d", &score);
} while(score != -1);
average = (double)sum / (double)i;
printf("%d, %d, %f, %d\n", max, min, average, sum);
}