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: 2516

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].

 
No Comment Found, Be the First to post comment!