// write a program in c to implement // Selection sort , BY :- SAAR #include int main() { int a[100], n, i, j, pos, swap; // pos= position printf("Enter size of array\n"); scanf("%d", &n); printf("Enter %d Numbers of array \n", n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n - 1; i++) { pos = i; for (j = i + 1; j < n; j++) { if (a[pos] > a[j]) pos = j; } if (pos != i) { swap = a[i]; a[i] = a[pos]; a[pos] = swap; } } printf("Sorted Array is: "); for (i = 0; i < n; i++) printf("%d ", a[i]); return 0; }
Enter size of array 7 Enter 7 Numbers of array 12 9 -3 55 100 69 420 Sorted Array is: -3 9 12 55 69 100 420
0 Comments