#include <stdio.h>
#include <stdlib.h> //for srand
#include <math.h>
#include <time.h>   //for seed for srand

#define swap(x, y, t) (t=x, x=y, y=t)

void sort(int[], int);

int main()
{
    while (1)
    {    
        int i, n;
        printf("Input the number of numbers to generate: ");
        scanf("%d", &n);
        int list[*&n];
        srand(time(NULL));

        for(i=0; i<n; i++)
        {
            list[i]=rand()%1000;
            if(i==n-1)
                printf("%d", list[i]);
            else
            printf("%d, ", list[i]);
        }

        printf("\nPress any key to sort...\n");
        system("pause");
        sort(list,n);

        for(i=0; i<n; i++)
        {
            if(i==n-1)
                printf("%d\n\n", list[i]);
            else
                printf("%d, ", list[i]);
        }
    }
    return 0;
}

void sort(int list[], int n)
{
    int i, j, min, temp;
    
    for(i=0; i<n; i++)
    {
        min=i;

        for(j=i+1; j<n; j++)
        {
            if (list[min]>list[j])
                swap(list[min], list[j], temp);
        }
    }
}