This Program is the combination of Both Ascending and descending order !!
It will show you how can you sort a array in both Ascending and descending order according to user's choice :
It will show you how can you sort a array in both Ascending and descending order according to user's choice :
/* This is a program for Perform Selection Sort in Ascending Order and Desceding order I combine the Method of Ascending and Descending in this using switch Statement
Method 1:
in 1 st phase :
In This we Selection first element and compare with all no .. if any number is smaller then replace it with first one that.
in Second phase :
we take second number and compare with remaining ones .. if any number is smaller then replace it with second one. this process so on ..
see below program.
Method 2:
in 1 st phase :
In This we Selction first element and compare with all no .. if any number is greater thn replace it with first one that.
in Second phase :
we take second number and comare with remaining ones .. if any number is greater thn replace it with second one.
this process so on ..
see below program.
Date : 21 April 2014
Time : 10:20 AM
*/
#include<stdio.h>
#include<conio.h>
#define max_size 5 // it can increase or decrease as per user requirement
int main()
{
int arr[max_size],i,tmp_no,j,ch;
printf("Enter 10 Numbers ");
for(i=0;i<max_size;i++)
{
printf("Enter Number %d : ",i+1);
scanf("%d",&arr[i]);
}
do{
printf("\n\t Menu ");
printf("\n1. Ascending Order ");
printf("\n2. Desending Order ");
printf("\n3. Any other to Exit");
printf("\n Choose your opiton : ");
scanf("%d",&ch);
switch(ch){
case 1:
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]);
}
break;
case 2:
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 descending Order : ");
for(i=0;i<max_size;i++)
{
printf("\n Number %d : %d",i+1,arr[i]);
}
break;
default: printf("\n Thanks Please Press any key to exit !!");
}
}while(ch<=2 && ch>=1);
getch();
return 0;
}
Download Source file : selection_sor_asc_dest.c
other impotent links : Ascending order using selection sort, 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 .
Program of Ascending and Descending Order using selection sort
Reviewed by Unknown
on
02:42
Rating:
No comments: