/*------------------------------------------------
【程序设计】
--------------------------------------------------
功能:求一批数中最大值和最小值的差。
------------------------------------------------*/
#define N 30
#include "stdlib.h"
#include <stdio.h>
void wwjt();
int max_min(int a[],int n)
{
/**********Program**********/
int i,max,min;
max = min = a[0];
for(i=1;i<n;i++)
if(a[i]>max)max = a[i];
else if(a[i]<min)min = a[i];
return max-min;
/********** End **********/
}
main()
{
int a[N],i,k;
for(i=0;i<N;i++)
a[i]=rand()%51+10;
for(i=0;i<N;i++)
{
printf("%5d",a[i]);
if((i+1)%5==0) printf("\n");
}
k=max_min(a,N);
printf("the result is:%d\n",k);
wwjt();
}
void wwjt()
{
FILE *IN,*OUT;
int n;
int i[30];
int o;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Read FILE Error");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Write FILE Error");
}
for(n=0;n<5;n++)
{
fscanf(IN,"%d",&i[n]);
}
o=max_min(i,5);
fprintf(OUT,"%d\n",o);
fclose(IN);
fclose(OUT);
}