注意给最大值和最小值赋初值

 

#include<cstdio>
#include<cstring>
char name[100],sname[100];
int main(){
    int m;
    scanf("%d",&m);
    int x,maxn,minn;
    scanf("%d",&x);
    maxn=x;minn=x;
    for (int i=2;i<=m;i++){
        scanf("%d",&x);
        if (x<minn) minn=x;
        if(x>maxn) maxn=x;
    }  
    printf("%d\n",maxn-minn);
    return 0;
}
View Code