PROGRAM MUST BE IN C LANGUAGE PLEASE ANSWER QUESTION IN COMP
PROGRAM MUST BE IN C LANGUAGE. PLEASE ANSWER QUESTION IN COMPLETE. THANKS!
Randomizing arrays is a significant problem in Computer Science. Sometimes we want to randomize an array of integers that contains all of the numbers between l and some number \"n\" but which does not omit any numbers in between or contain any duplication of numbers. (Such a listing of numbers is called a permutation.) The purpose of this exercise is to demonstrate one technique for randomizing an array of permutations. It also gives us some exposure to the use of the random number generator in C. In addition to the function that randomizes the permutation array, please implement three other functions: a function that prints the array, a function that sorts the array, and a function that swaps two integers. These are described below Your program should perform the following steps: 1) In the main0 function a) Create an array of ints of size 100. b) Initialize the array with sequential numbers from 100 down to 1. (This will create a permutation.) c) Call the following functions in the following order: ll print original order i) printArray (int inputArr[], int size) ii) randomize Array (int inputArr0, int size) print randomized order iii) print Array (int inputArr0, int size) iv print sorted order v) printArray (int input Arrl], int size) 2) Function descriptions a) void printArray (int inputArrll, int size)Solution
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void printArray(int arr[], int size){
int i, j;
for(i = 0; i < size / 10; i++){
for(j = 0; j < 10; j++){
printf(\"%5d \", arr[i * size / 10 + j]);
}
printf(\"\ \");
}
printf(\"\ \");
}
void swap(int *x, int *y){
int temp = *x;
*x = *y;
*y = temp;
}
void randomizeArray(int arr[], int size){
srand(10);
int currPos = 0;
for(currPos = 0; currPos < 100; currPos++){
int index = rand() % 100;
swap(&arr[index], &arr[currPos]);
}
}
void bubbleSortArray(int arr[], int size){
int i, j;
for(i = size - 1; i > 0; i--){
for(j = 0; j <= i - 1; j++){
if(arr[j] > arr[j + 1]){
swap(&arr[j], &arr[j + 1]);
}
}
}
}
int main(){
int arr[100], size = 100, i;
for(i = 0; i < size; i++){
arr[i] = size - i;
}
printArray(arr, size);
randomizeArray(arr, size);
printArray(arr, size);
bubbleSortArray(arr, size);
printArray(arr, size);
}

