题解 | #最高分与最低分之差#
最高分与最低分之差
http://www.nowcoder.com/practice/e0e4f81dcd55408a8973f8033bbeb1d2
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
int Sort(const void* a, const void* b)
{
return *(int*)a-*(int*)b;
}
int main()
{
int n = 0, m = 0;
int* p = NULL;
scanf("%d", &n);
p = (int*)malloc(sizeof(int) * n);
if(p==NULL)
return 0;
for (int i = 0; i < n; i++)
{
scanf("%d", &m);
*(p + i) = m;
}
qsort(p, n, sizeof(int), Sort);
printf("%d\n", *(p + n - 1) - *(p));
free(p);
p=NULL;
return 0;
}