#include #include unsigned long cmp(const unsigned long *x, const unsigned long *y) { return (*x < *y) ? -1 : (*x > *y) ? 1 : 0; } int main(void) { unsigned long n; unsigned long *x; unsigned long tmp; unsigned long min = 1000001; int i, j; scanf("%lu", &n); x = calloc(n, sizeof(unsigned long)); if (x == NULL) printf("領域確保失敗!"); else { for (i = 0; i < n; i++) scanf("%lu", &x[i]); qsort(x, n * sizeof(unsigned long) / sizeof(unsigned long), sizeof(unsigned long), (int (*)(const void *, const void *))cmp); for (i = 0; i < n; i++) { if (x[i + 1] - x[i] < min) if (x[i + 1] != x[i]) min = x[i + 1] - x[i]; } if (n == 1 || min == 1000001) printf("%lu\n", 0); else printf("%lu\n", min); free(x); } return 0; }