求好心人帮看下代码
新手自学C,求帮帮忙!!! 求数组中最大值和最小值的差 代码如下:#include<stdio.h>
double gap(double ar[], int n);
int main(void)
{
double num[10]={23.1, 2.1 ,32.1, 66.1, 1.1, 5.1, 25.1, 7.1, 3.1, 20.1};
printf("该数组中最大值和最小值的差是:%f\n", gap(num, 10));
return 0;
}
double gap(double ar[], int n)
{
int i;
double max=0.0,min=0.0;
for(i=0;i<n;i++)
{
if(max<=ar[i])
max=ar[i];
if(min>=ar[i])
min=ar[i];
}
return (max-min);
}