Skip to content

Commit

Permalink
Merge pull request #1 from Jasneet410/Jasneet410-patch-1
Browse files Browse the repository at this point in the history
Selection_Sort
  • Loading branch information
Jasneet410 authored Oct 2, 2020
2 parents 440be04 + e05066d commit c658c0c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions C/Selection_Sort
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<stdio.h>
int main(){
/* Here i & j for loop counters, temp for swapping,
* count for total number of elements, number[] to
* store the input numbers in array. You can increase
* or decrease the size of number array as per requirement
*/
int i, j, count, temp, number[25];

printf("Enter the number of elements : ");
scanf("%d",&count);

printf("Enter %d elements: ", count);
// Loop to get the elements stored in array
for(i=0;i<count;i++)
scanf("%d",&number[i]);

// Logic of selection sort algorithm
for(i=0;i<count;i++){
for(j=i+1;j<count;j++){
if(number[i]>number[j]){
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
}

printf("Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);

return 0;
}

0 comments on commit c658c0c

Please sign in to comment.