[ create a new paste ] login | about

Link: http://codepad.org/qmOtI1e3    [ raw code | output | fork ]

C, pasted on Jul 5:
#include <stdio.h>

void sort(int a[],int lengh)
{
    int tmp,i;
    while (lengh-- >= 0) {
        for (i = 0; i < lengh; i++) {
            if (a[lengh] > a[i]) {
                tmp = a[lengh];
                a[lengh] = a[i];
                a[i] = tmp;
            }
        }
    }
} 

int main(void)
{
    int array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int i;
    int length = sizeof(array) / sizeof(array[0]);

    for (i = 0; i < length; i++) {
        printf("%d ", array[i]);
    }
    printf("\n");

    sort(array, length);

    for (i = 0; i < length; i++) {
        printf("%d ", array[i]);
    }
    printf("\n");
    return 0;
}


Output:
1
2
0 1 2 3 4 5 6 7 8 9 
9 8 7 6 5 4 3 2 1 0 


Create a new paste based on this one


Comments: