All pastes #1536885 Raw Edit

Untitled

public c v1 · immutable
#1536885 ·published 2009-08-20 21:05 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>int* removeElements(int* array, int x, int y, int n) {    int *new;    int i = 0, j = 0;    new = malloc((n-2)*sizeof(int));    while (i < n) {        if (array[i] != array[x] || array[i] != array[y])            new[j++] = array[i];        i++;    }    free(array);    return new;}void calcMinPair(int* array, int n) {    int i = 0, j = 0;    int x, y, val = 0;    int min = 100;    x = 0; y = 0;    while (i < n) {        j = 0;        while (j < n) {            if (i != j) {                val = array[i] - array[j];                if (val < 0)                    val = 0 - val;                if (val < min) {                    min = val;                    x = i;                    y = j;                }            }            j++;        }        i++;    }    array = removeElements(array, x, y, n);}int main(int argc, char *argv[]) {    int array[10] = {2, 3, 10, 5, 8, 9, 7, 3, 5, 2};    int counter = 10, i;    while (counter > 1) {        i = 0;        while (i < counter)            printf("%d ", array[i++]);        printf("\n");        calcMinPair(array, counter);        counter = counter - 2;    }    return 0;}