Resources » Articles/Knowledge Sharing » Computer & Technology

Write a Program To Sort the Elements Of an Array using “SELECTION SORT”.


Updated: Category: Computer & Technology
Author: Member Level: SilverPoints: 2


Write a Program To Sort the Elements Of an Array using “SELECTION SORT”.



Write a Program To Sort the Elements Of an Array using “SELECTION SORT”.

SOURCE CODE:



#include
#include
void main()
{
int loc,temp,i,j,a[20],n,count=1;
clrscr();
printf("\nThis Program is Used to sort the Elements of Array Using SELECTION SORT\n");
printf("\n\tEnter the Number of Elements:");
scanf("%d",&n);
printf("\n\n\tEnter the Elements:");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
temp=a[i];
for(j=i+1;j<=n;j++)
{
if(temp>a[j])
{
temp=a[j];
count=j;



}
}
loc=a[i];
a[i]=temp;
a[count]=loc;

}




printf("\n\tThe Sorted Array is :");
printf("\n\n\t\t");
for(i=1;i<=n;i++)
{
printf("\t%d",a[i]);
}
getch();
}


OUTPUT

This program is used to sort the element of array using Selection Sort

Enter the number of elements: 5
Enter the elements of Array:77 33 44 11 21
The sorted Array is as:
11 21 33 44 77


Did you like this resource? Share it with your friends and show your love!




Responses to "Write a Program To Sort the Elements Of an Array using “SELECTION SORT”."

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index
    Complete the action items below to enter to win an iPad Mini from India Study Channel! in India Study Channel - Locker on LockerDome
    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

     
    ISC Technologies, Kochi - India. © All Rights Reserved.