#5
by box » 1年前
typoその他があったので一部手を加えました。よかったら適当に使ってください。
コード:
#include <stdio.h>
int main(void)
{
int n, max, min, total = 0, times = 0;
while (1) {
printf("input integer(if you input 0, this program will end) ");
scanf("%d", &n);
if (n == 0) {
break;
}
if (times == 0) {
max = min = n;
}
else {
if (n > max) {
max = n;
}
if (n < min) {
min = n;
}
}
printf("current max is %d\n", max);
printf("current min is %d\n", min);
times++;
total += n;
}
if (times != 0) {
printf("total is %d\n", total);
printf("iteration is %d\n", times);
printf("average is %f\n", (double) total / times);
printf("max is %d\n", max);
printf("min is %d\n", min);
}
return 0;
}
typoその他があったので一部手を加えました。よかったら適当に使ってください。
[code]
#include <stdio.h>
int main(void)
{
int n, max, min, total = 0, times = 0;
while (1) {
printf("input integer(if you input 0, this program will end) ");
scanf("%d", &n);
if (n == 0) {
break;
}
if (times == 0) {
max = min = n;
}
else {
if (n > max) {
max = n;
}
if (n < min) {
min = n;
}
}
printf("current max is %d\n", max);
printf("current min is %d\n", min);
times++;
total += n;
}
if (times != 0) {
printf("total is %d\n", total);
printf("iteration is %d\n", times);
printf("average is %f\n", (double) total / times);
printf("max is %d\n", max);
printf("min is %d\n", min);
}
return 0;
}
[/code]