C program for Sorting 10 numbers using pointer

#include <stdio.h>
void bubblesort(int *, int);
void swap(int *, int *);
main()

{
        int arr[10], i;
        printf("Enter 10 numbers:\n");
        for(i=0;i<10;++i) {
                scanf("%d",(arr+i));
        }
        bubblesort(arr, 10);
        printf("The sorted list is: ");
        for(i=0;i<10;++i) {
                printf("%d ",*(arr+i));
        }
        printf("\n");
}

void bubblesort(int *p, int n) {
        int temp, i, j;
        for(i=0;i<n-1;++i) {
                for(j=i+1;j<n;++j) {
                        if(*(p+i) > *(p+j)) {
                                swap(p+i,p+j);
                        }
                }
         }
}

void swap(int *a, int *b) {
        int temp;
        temp = *a;
        *a = *b;
        *b = temp;
}

                               
       

Post a Comment

0 Comments