Why add min=[0] can seek a minimum
But Max didn't write or make
Why don't write Max=a [0] min=a [0] under the condition of
Max that min may not make
# define N 30
Int main ()
{
Int a [N], min=0, Max=0, I=0, sum=0, avg=0;
Printf (" please enter the 30 students achievement: ");
for (i=0; I & lt; N; I++)
{
Scanf_s (" % d ", & amp; A [I]);
}
for (i=0; I & lt; N; I++)
{
The sum +=a [I];
If (min & gt; A [I])
{
Min=a, [I].
}
If (Max & lt; A [I])
{
Max=a, [I].
}
}
Avg=sum/N.
Printf (" maximum=% d \ n ", Max).
Printf (" minimum value=% d \ n ", min);
Printf (" average=% d \ n ", avg);
return 0;
}
CodePudding user response:
# include & lt; stdio.h>
# define N 30
Int main ()
{
Int a [N], min, Max, I, sum, avg;
Printf (" please enter % d students grades \ n ", n);
for (i=0; I & lt; N; I++) {
While (1) {
Printf (" % d student achievement: ", I + 1);
fflush(stdout);
The rewind (sstdin);
If (1==scanf_s (" % d ", & amp; A [I]) {
If (0 & lt;=a [I] & amp; & A [I] <=100) break;
}
Printf (" input format error! Please re-enter the \ n ", n);
}
}
Sum=0;
Min=Max=a [0];
for (i=1; I & lt; N; I++) {
The sum +=a [I];
If (a [I]If (a [I] & gt; Max) Max=a [I];
}
Avg=sum/N.
Printf (" maximum=% d \ n ", Max).
Printf (" minimum value=% d \ n ", min);
Printf (" average=% d \ n ", avg);
return 0;
}
CodePudding user response:
Line 11 rewind (sstdin); Should be rewind (stdin);CodePudding user response:
Because you all Numbers greater than zero, so can't compareCodePudding user response:
Line 12 if (1==scanf_s (" % d ", & amp; A [I]) {should for the if (1==scanf_s (" % d ", & amp; A [I]) {CodePudding user response:
Usually value initialized to minimum, the minimum can be initialized to the largest,CodePudding user response:
The original poster can run this code, and see what the Max min avg output, look for feeling:
30 # define NInt main ()
{
Int a [N], min, Max, I, the sum=0, avg=0;
/* printf (" please enter the 30 students achievement: ");
for (i=0; I & lt; N; I++)
{
Scanf_s (" % d ", & amp; A [I]);
}
for (i=0; I & lt; N; I++)
{
The sum +=a [I];
If (min & gt; A [I])
{
Min=a, [I].
}
If (Max & lt; A [I])
{
Max=a, [I].
}
}
Avg=sum/N. */
Printf (" maximum=% d \ n ", Max).
Printf (" minimum value=% d \ n ", min);
Printf (" average=% d \ n ", avg);
system("pause");
return 0;
}
Maximum minimum size, are limited, within the scope of the size of the value is relative, is within the scope of a certain size, size must be in a specific area, then go to compare, for example to compare the height of a preschool children, if set initial value: Max=adult height, finally the Max also can find them?
CodePudding user response: