HOME

Tuesday, April 18, 2017

SELECTION SORT - C PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j, temp, n, a[20];
    printf("Enter size of array\n");
    scanf("%d",&n);
    printf("Enter %d value\n",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    printf("sorted array is:\n");
    for(i=0;i<n;i++)
    {
        printf("%d\n",a[i]);
    }
    getch();
}

No comments:

Post a Comment