11.04 The first question of the experimental class is often a mentality

Take the maximum and minimum values ​​of a set of data: (the first question of the experiment class is so stupid for me)
First define two variables max and min. Note that this is a variable and not a function, so it will only be used later. A comparative role. For example, if (c>max) max=c. It is to compare each data of this group of data with max, and take the larger one.
#include <stdio.h>
int main()
{
int a,b,c,max,min;
while(scanf("%d",&a)!=EOF)
{scanf("%d",&c);
max =min=c;
if(a==0) break;
for(b=1;b<a;b++)
{scanf("%d",&c);
if(c>max)
max=c;
if(c <min)
min=c;
}
printf("%d\n",(max-min)*2);
}
}

Guess you like

Origin blog.51cto.com/14951163/2546868