This is a program for Perform Selection Sort in Ascending Order
Method :
in 1 st phase :
In This we Selction first element and compare with all no ..if any number is smaller thn replace it with first one that.
in Second phase :
we take second number and comare with remaining ones ..if any number is smaller thn replace it with second one. this process will be so on ..
see below program.
#include<stdio.h> #include<conio.h> #define max_size 10 int main() { int arr[max_size],i,tmp_no,j; printf("Enter 10 Numbers "); for(i=0;i<max_size;i++) { printf("Enter Number %d : ",i+1); scanf("%d",&arr[i]); } for(i=0;i<max_size-1;i++){ for(j=i+1;j<max_size;j++) { if(arr[i]>arr[j]){ tmp_no = arr[i]; arr[i] = arr[j]; arr[j]= tmp_no; } } } printf("\nYour Array in Ascending Order : "); for(i=0;i<max_size;i++) { printf("\n Number %d : %d",i+1,arr[i]); } getch(); return 0; }
Download Source file : selection_sort_ascending.c
other impotent links : Ascending order using selection sort, Descending order using selection sort,Ascending and Descending order using selection sort
keywords : Ascending and descending program using selection sort, selection sort, selection sort in c, sorting in c, Ascending and descending in array .
Ascending Order Using Selection Sort
Reviewed by Unknown
on
02:54
Rating:
No comments: