C Program to Sort Array Elements Using Selection Sort Algorithm

The selection sort algorithm sorts an array by repeatedly finding the minimum element (for ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.

	#include ;
	int main()
	{
	 int num[5],size=5,i,j,temp,min_index;
	 
	 printf("enter %d elements of array : ",size);
	 for(i=0;inum[j]){
				   min_index=j;
				   }
		}
		
		if(i!=min_index)
		{
				temp=num[i];
				num[i]=num[min_index];
				num[min_index]=temp;
		}
	 }


	 printf("Array Element After Sorting....\n");
	 for(i=0;i

Output

	enter 5 elements of array : 12
	23
	34
	2
	45
	Array Element After Sorting....
	2 12 23 34 45