Pages

Wednesday, March 26, 2014

C program to sort numbers in an array using quick sort

/*to sort the number in ascending order*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,i,j,a[25],temp;
    printf("How many numbers?");
    scanf("%d",&n);
    printf("enter %d number",n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        for (j=i+1;j<n;j++)
        {
            if (a[i]>a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    printf("\n Sorted Number are: ");
    for(i=0;i<n;i++)
        printf("%d \t",a[i]);
    system("pause");
    return 0;
}

No comments:

Post a Comment