Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NMAX 101
- void swap(int* a, int* b) {
- int tmp = *a;
- *a = *b;
- *b = tmp;
- }
- int main(void) {
- static int arr[NMAX];
- int n;
- scanf_s("%d", &n);
- for (int i = 0; i < n; i++) {
- scanf_s("%d", &arr[i]);
- }
- for (int i = 0; i < n - 1; i++) {
- int minId = i;
- for (int j = i + 1; j < n; j++) {
- if (arr[minId] > arr[j]) {
- minId = j;
- }
- }
- swap(&arr[i], &arr[minId]);
- }
- for (int i = 0; i < n; i++) {
- printf("%d ", arr[i]);
- }
- putchar('\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement