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 <algorithm>

using namespace std;

int abs(int a,int b){

  int result;

  if(a<b)
    result=b-a;
  else
    result=a-b;
  return result;
};

int main(void){

  int n;
  int min=1000001;
  int  temp;
  
  while(cin >> n,n){

      vector <int> student(n);
    
    for(int i=0;i<n;i++){
      cin >> student[i];
    }

    sort(student.begin(),student.end(),greater<int>());

    for(int i=0;i<n;i++){
      
      temp=abs(student[i],student[i+1]);
      //cout << temp <<endl;

      if(min>temp)
	min=temp;
    }

    cout << min <<endl;

    student.clear();
    min=1000001;

  }

  return 0;
  
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];
        sort(a.begin(), a.end());
        int ans = INF;
        for(int i = 0; i < n - 1; i++){
            ans = min(ans, (int)abs(a[i + 1] - a[i]));
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;

    if (n == 0) {
      break;
    }
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
  
    sort(a.begin(), a.end());

    int mind = 1000001;
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d < mind) {
	mind = d;
      }
    }

    cout << mind << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main( ){
  while(1){
    double D,E,min;
    cin>>D>>E;
    if(D==0&&E==0)break;
    for(int i=0;i<=D;i++){
      double l=fabs(sqrt(pow(D-i,2)+pow(i,2))-E);
      if(i==0)min=l;
      if(l<min)min=l;
    }
    printf("%f\n",min);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	while (1){
		int n;
		vector<int> student;
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++){
			int s;
			cin >> s;
			student.push_back(s);
		}
		sort(student.begin(),student.end());
		int min = 100;
		for (int i = 0; i < n - 1; i++){
			int gap = student[i+1] - student[i];
			if (gap < min) min = gap;
		}
		cout << min << endl;
	}


	return 0;
}

C++: #include <iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define INF 9999999

int main() {

	int n, an;
	vector<int> vec;
	int ans = INF;

	while (1) {

		cin >> n;
		if (n == 0) break;
		//??\???
		for (int i = 0; i < n; i++) {
			cin >> an;
			vec.push_back(an);
		}
		//?????????
		sort(vec.begin(), vec.end());
		//??????????°?????¨????
		for (int i = 0; i < n - 1; i++) {
			if (vec[i + 1] - vec[i] < ans) {
				ans = vec[i + 1] - vec[i];
			}
			if (ans == 0) break; //????°?????????¢?´¢????????¢???
		}
		//??????
		cout << ans << endl;
		//?????????
		vec.clear();
		ans = INF;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
int a[1000];
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++)cin >> a[i];
		sort(a, n);
		int ans = inf;
		for (int i = 1; i < n; i++) {
			ans = min(ans, a[i] - a[i - 1]);
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int a[10000000];

int main(){
  int n;
  while(1){
    cin>>n;
    int mini=INF;
    if(n==0)break;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-1;i++){
      mini=min(mini,a[i+1]-a[i]);
    }
    cout<<mini<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector<int> a(n);
        rep(i, n) cin >> a[i];
        sort(a.begin(), a.end());
        int ans = a[1] - a[0];
        rep(i, n) if (i) ans = min(ans, a[i] - a[i - 1]);
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>

#define rep(i,n) for(i=0;i<(n);i++)

using namespace std;

int main() {
	int n,i,ans;
	
	while(1){
		cin>>n;
		if(n==0){
			break;
		}
		int a[n]={0};
		rep(i,n){
			cin>>a[i];
		}
		sort(a,a+n);
		ans=a[1]-a[0];
		
		for(int i=1;i<n-1;i++){
			if(ans>a[i+1]-a[i]){
				ans=a[i+1]-a[i];
			}
		}
		cout<<ans<<endl;
	}
	
	
	// your code goes here
	return 0;
}

C++: using namespace std;
typedef long long ll;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
 
int main(){
    int N;
    cin >> N;
    vector<ll> ans;
    while (N!=0)
    {
        vector<ll> a;
        a.resize(N);
        for (int i = 0; i < N; i++) cin >> a[i];
        ll thismin = 1e10;
        for (int i = 0; i < N;i++) {
            for (int n = 0; n < N; n++) {
                if (n == i) continue;
                thismin = min(thismin, abs(a[i] - a[n]));
            }
        }
        ans.push_back(thismin);
        cin >> N;
    }
    for (int i = 0; i < ans.size();i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,min = 1000000,temp=0,i;
  while(1){
    cin >> n;
    if(n==0) break;
    int a[1000];
    for(i=0;i<n;i++){
    cin >> a[i];
    }
    for(int j=0;j<n-1;j++){  
      for(i=0;i<n-1;i++){
	if(a[i]>a[i+1]){
	  swap(a[i],a[i+1]);
	}
      }
    }
    
    for(i=0;i<n-1;i++){
      if((a[i+1]-a[i])<min){
	min = (a[i+1]-a[i]);
      }
    }
    if(min<0) min *= -1;
    cout << min << endl;
    min=1000000;
    temp=0;
    }
  return 0;
}