Exchange Sort

#include <stdio.h>
int main()
{
int arr[100];
int size, i, j, temp;

printf("Enter size of array :: ");
scanf("%d", &size);

printf("\nEnter elements in array :: \n ");
for(i=0; i<size; i++)
{
printf("\nEnter %d element in an array :: ",i+1);
scanf("%d", &arr[i]);
}

for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
    if(arr[j] < arr[i])
    {
    temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
    }
}
}
printf("\nElements of array in sorted ascending order :: ");
for(i=0; i<size; i++)
{
printf(" %d ", arr[i]);
}
return 0;
}

Comments

Popular posts from this blog

Data Structure Lab CSL 201 Manual KTU - Dr Binu V P-9847390760

Singly Linked List Implementation

Binary search Tree Implementation and Traversal