[ create a new paste ] login | about

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

C, pasted on Apr 11:
   #include <stdio.h>

    void sort(int* number, int n){

         /*Sort the given array number , of length n*/     

        int temp=0,j,i;
            for(i=1;i<n;i++)
            {
                for(j=0;j<n-i;j++)
                {
                    if(number[j] >number[j+1])
                    {
                        temp=number[j];
                        number[j]=number[j+1];
                        number[j+1]=temp;
                    }
                }
            }
        }

    int main(){

        int n = 20;
        int *ptr = malloc(n * sizeof *ptr);
        int i = 0;

        while (i< n)
        {
             ptr[i]=rand() %100;
             i++;
        }
        int j = 0;
        while (j < n)
        {
            printf("%d , ", ptr[j]);
            j++;
        }
        void sort(ptr, n);
        printf("\n");

        int x = 0;
        while (x < n)
        {
            printf("%d , ", ptr[x]);
            x++;
        }
    }


Output:
1
2
3
83 , 86 , 77 , 15 , 93 , 35 , 86 , 92 , 49 , 21 , 62 , 27 , 90 , 59 , 63 , 26 , 40 , 26 , 72 , 36 , 
83 , 86 , 77 , 15 , 93 , 35 , 86 , 92 , 49 , 21 , 62 , 27 , 90 , 59 , 63 , 26 , 40 , 26 , 72 , 36 , 
Exited: ExitFailure 5


Create a new paste based on this one


Comments: