Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		an := make([]int, n)
		min := 1000000
		for i := 0; i < n; i++ {
			an[i] = nextInt()
		}
		sort.Ints(an)
		for i := 1; i < n; i++ {
			sub := an[i] - an[i-1]
			if min > sub {
				min = sub
			}
		}
		fmt.Println(min)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;
using vs=vector<string>;
using vpii=vector<pii>;
using si=set<int>;

#define REP(i,a) for(int i=0;i<a;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a) for(int i=(a)-1;i>=0;i--)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define out(S) cout<<(S)<<endl;
#define beginend(v) (v).begin(),(v).end()
#define IfOut(condition,text) if(condition){out(text);return 0;}
#define IfOutElse(condition,if_text,else_text) if(condition){out(if_text);return 0;}else{out(else_text);return 0;}
#define mod(s) ((s)%(ll)(1e9+7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a*modpow((ll)b,(ll)(1e9+5))))
#define pb(i) push_back(i)
#define fst first
#define snd second
#define Foreach(item,collection) for(auto item:collection)
#define INF (int)1e10
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}
ll sum(vi v) {ll sum=0;Foreach(i,v){sum+=i;}return sum;}
#define ShowAll(v) Foreach(i,v) out(i);


int main(){
    vi ans;
    int n;
    while (cin>>n,n)
    {
        vi a(n);
        REP(i,n)cin>>a[i];
        sort(beginend(a));
        int m=INF;
        REP(i,n-1) m=min(m,a[i+1]-a[i]);
        ans.pb(m);
    }
    
    ShowAll(ans);
    return 0;
}

C++: #include <iostream>
#include <stdlib.h>

int* merge(int a[], int n) {
    if (n == 1) {
        return a;
    }
    int* a1 = (int*)malloc(n/2 * sizeof(int));
    int* a2 = (int*)malloc((n-n/2) * sizeof(int));
    for(int i = 0; i < n/2; i++) {
        a1[i] = a[i];
    }
    for(int i = n/2; i < n; i++) {
        a2[i-n/2] = a[i];
    }
    a1 = merge(a1,n/2);
    a2 = merge(a2,n-n/2);
    int i1 = 0;
    int i2 = 0;
    for(int i = 0; i < n; i++) {
        if(i2 == n-n/2 || (i1 != n/2 && a1[i1] < a2[i2])) {
            a[i] = a1[i1];
            i1++;
        } else {
            a[i] = a2[i2];
            i2++;
        }
    }
    return a;
}

int main(){
    int n;
    std::cin >> n;
    while(n != 0) {
        int* a = (int*)malloc(n * sizeof(int));
        for(int i = 0; i < n; i++) {
            std::cin >> a[i];
        }
        a = merge(a,n);
        int min = a[1] - a[0];
        for(int i = 1; i < n-1; i++) {
            int tmp = a[i+1] - a[i];
            if (tmp < min) {
                min = tmp;
            }
        }
        std::cout << min << std::endl;
        std::cin >> n;
    }
    return 0;
}