Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Selection sort

Posted By: Rainart Fischer     Category: C Programming     Views: 4781

Program of Selection sort.

Code for Selection sort in C Programming

#include <stdio.h>
#include <conio.h>

void main( )
{
    int arr[5] = { 25, 17, 31, 13, 2 } ;
    int i, j, temp ;

    clrscr( ) ;

    printf ( "Selection sort.\n" ) ;
    printf ( "\nArray before sorting:\n") ;

    for ( i = 0 ; i <= 4 ; i++ )
        printf ( "%d\t", arr[i] ) ;

    for ( i = 0 ; i <= 3 ; i++ )
    {
        for ( j = i + 1 ; j <= 4 ; j++ )
        {
            if ( arr[i] > arr[j] )
            {
                temp = arr[i] ;
                arr[i] = arr[j] ;
                arr[j] = temp ;
            }
        }
    }

    printf ( "\n\nArray after sorting:\n") ;

    for ( i = 0 ; i <= 4 ; i++ )
        printf ( "%d\t", arr[i] ) ;

    getch( ) ;
}
[/Code]
  
Share: 

 
 

Didn't find what you were looking for? Find more on Selection sort Or get search suggestion and latest updates.

Rainart Fischer
Rainart Fischer author of Selection sort is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Sachin Raj from India Comment on: Aug 21
Thank you for give a such a website...i can get everything i need but i was searched here for some real time examples for some sorting and searching techniques......bt i culdnt get it if it is there in it plz help me!!!

View All Comments