Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2) Function descriptions: a) void printArray (int inputArr[], int size ) i) This

ID: 3531745 • Letter: 2

Question


2) Function descriptions:


a) void printArray (int inputArr[], int size )


i) This function will print the array contents, 10 numbers per line. Each
number should be right justified in a field of size 5.


b) void randomizeArray (int inputArr[], int size)

i) This function will randomize the array according to the algorithm given
below.

ii) Algorithm:

(1) Use srand() to seed the random number generator witha seed of 10
as we discussed in class.

(2) Set a counter variable called currPosto point to the first element
in the array, 0.

(3) Loop currPosfrom 0 to 99, performing the following steps

(a) Randomly choose an array index between 0 and 99.

(b) Exchange the element at currPoswith the randomly
chosen element by using the swap()function.

(c) Increment currPos.

Explanation / Answer

void printArray (int inputArr[], int size ){

int i;

for(i=0;i<size;i++){

printf("%.5d",inputArr[i]);

if((i+1)==0)

printf(" ");

}


void randomizeArray (int inputArr[], int size){

srand((unsigned int)time(NULL));//seed time

int* currPos=inputArr;

int i,choice;

for(i=0;i<99;i++){

choice=rand()%size;

swap(currPos,inputArr[choice]);

currPos++;// increment

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote