Home > Back-end >  An array of
An array of

Time:11-16

Input n (1 n & lt;=10) positive integers and save to array, calculate the maximum, minimum, average, and the maximum value, how much is the minimum value in the array subscript, respectively

CodePudding user response:

Write a, you see line not line?
 # include & lt; Stdio. H> 
# define LEN 10

Int main (void)
{
Int a [LEN], n, I;
Int maxpos minpos, sum;

/* enter the value of n */
Printf (" input n: \ n ");
The scanf (" % d ", & amp; N);

/* n input array values */
Printf (" input n Numbers: \ n ");
for(i=0; i{
The scanf (" % d ", & amp; A [I]);
}

Initialization/* */
Maxpos=minpos=0;
Sum=a, [0].

/* scanning array, look for the maximum, minimum, and calculation and */
for(i=1; i{
Sum=sum + a [I];
If (a [I] & gt; A [maxpos]) maxpos=I;
If (a [I] }

/* the output */
Printf (" max_value: % d \ \ t tmin_value: \ n \ t % d ", a [maxpos], a [minpos]);
Printf (" % d \ tmin_positon max_positon: \ t: \ t % d \ n ", maxpos, minpos);
Printf (" average_value: \ t % 2 f \ n ", 1.0 * sum/n);

return 0;
}

CodePudding user response:

This topic is not difficult, write their own best,
  • Related