#include
#include
#include
Copyright By PowCoder代写 加微信 powcoder
void selectionSort(int array[], int n);
void swap(int *px, int *py);
void printArray(int array[], int n);
int main() {
int array[10];
int i, n = 10;
// Seed the random number generator with the current time
srand(time(NULL));
// Generate a random number between 1 and 100 for each element in the array
for (i = 0; i < n; i++) {
array[i] = rand() % 100 + 1;
// Print the unsorted array
printf("Unsorted array: ");
printArray(array, n);
// Sort the array using selection sort
selectionSort(array, n);
// Print the sorted array
printf("Sorted array: ");
printArray(array, n);
void selectionSort(int array[], int n) {
int i, j, min_idx;
// One by one move boundary of unsorted subarray
for (i = 0; i < n-1; i++) {
// Find the minimum element in unsorted array
min_idx = i;
for (j = i+1; j < n; j++) {
if (array[j] < array[min_idx]) {
min_idx = j;
// Swap the found minimum element with the first element
swap(&array[min_idx], &array[i]);
void swap(int *px, int *py) {
int temp = *px;
*px = *py;
*py = temp;
void printArray(int array[], int n) {
for (i = 0; i < n; i++) {
printf("%d ", array[i]);
printf("\n");
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com