Question: Please program Merge Sort and test on array of 200 random characters. Hint: C integer division always returns an int, not a fraction #include #include
Please program Merge Sort and test on array of 200 random characters. Hint: C integer division always returns an int, not a fraction
#include
void selectionSort(int arr[], int n);
int main() {
//declaring the array and generating 50 random numbers between 0 and 99
int arr[50]; for(int i=0;i<50;i++) { arr[i] = (rand() % 100) ;
}
//printing input array in rows of 20 numbers
printf("INPUT ARRAY : ");
int temp20 = 19;
for(int i=0;i<50;i++) { printf("%d ",arr[i]); if(i%temp20 == 0 && i!=0) { printf(" "); temp20 = temp20 + 20;
}
}
//performing selection sort
selectionSort(arr,50);
printf(" "); printf(" ");
//printing output array in rows of 10 numbers
printf("OUTPUT ARRAY : ");
int temp10 = 9;
for(int i=0;i<50;i++) { printf("%d ",arr[i]); if(i%temp10 == 0 && i!=0) { printf(" "); temp10 = temp10 + 10;
}
}
return 0;
}
void selectionSort(int arr[], int n)
{
int i, j, min_idx;
for (i = 0; i < n-1; i++)
{
min_idx = i;
for (j = i+1; j < n; j++) if (arr[j] < arr[min_idx])
min_idx = j;
int temp = arr[min_idx]; arr[min_idx] = arr[i]; arr[i] = temp;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
