C Program For Selection Sort

/*Selection Sort*/

#include<stdio.h>
#include<conio.h>
main()
{
int a[10],n,i,j,pos,temp;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
 for(i=0;i<n;i++)
 {
 printf("Enter the value of a[%d]\n",i);
 scanf("%d",&a[i]);
 }


 for(i=0;i<n;i++)
 {
 pos=i;
  for(j=i+1;j<n;j++)
  {
   if (a[j]<a[pos])
   {
   pos=j;
   }
  }
 temp=a[i];
 a[i]=a[pos];
 a[pos]=temp;
 }

 printf("The array after the sorting is \n");

 for(i=0;i<n;i++)
 {
 printf("a[%d]=%d\n",i,a[i]);
 }
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment