Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //selecton sort
- void selection_sort (int A[], int n)
- {
- int k ,j , minimum_position, swap;
- for (k = 0; k< n; k++)
- {
- minimum_position = k;
- for(j = k +1; j<n; j++)
- {
- if(A[j]< A[minimum_position])
- minimum_position = j;
- }
- //swap(A[k], A[minimum_position]);
- swap = A[k];
- A[k]= A[minimum_position];
- A[minimum_position]= swap;
- }
- }
- int main()
- {
- int A [100];
- int k, n ,j ,minimum_position,swap;
- printf("Enter the number of elements you want to sort = ");
- scanf("%d", &n);
- for (k=0; k<n; k++)
- {
- printf("\nEnter the element %d: ", k+1);
- scanf("%d", &A[k]); // not put space after d :>
- fflush(stdin);
- }
- selection_sort(A, n);
- for (k=0; k<n; k++)
- {
- printf("%d\n", A[k]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement