結果如下。若輸入的數字沒在0 -100 之間會提示,重新輸入
#include <stdio.h>
#include <stdlib.h>
void main(void)
{
int min = 0;
int max = 0;
int number[10] = {0};
int i = 0;
for (i = 0; i < 10; i++)
printf("請輸入第%d個數:", i + 1);
while (1)
scanf("%d", &number[i]);
if (number[i] >= 0 && number[i] <= 100)
break;
}
else
printf("請輸入0-100之間的數字 !!!\n");
if (i == 0)
min = max = number[0];
if (max < number[i])
max = number[i];
if (min > number[i])
min = number[i];
printf("最大值: %d\t最小值:%d\n", max, min);
system("pause");
結果如下。若輸入的數字沒在0 -100 之間會提示,重新輸入
#include <stdio.h>
#include <stdlib.h>
void main(void)
{
int min = 0;
int max = 0;
int number[10] = {0};
int i = 0;
for (i = 0; i < 10; i++)
{
printf("請輸入第%d個數:", i + 1);
while (1)
{
scanf("%d", &number[i]);
if (number[i] >= 0 && number[i] <= 100)
{
break;
}
else
{
printf("請輸入0-100之間的數字 !!!\n");
}
}
if (i == 0)
{
min = max = number[0];
}
else
{
if (max < number[i])
{
max = number[i];
}
if (min > number[i])
{
min = number[i];
}
}
}
printf("最大值: %d\t最小值:%d\n", max, min);
system("pause");
}