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

please consider this code #include #include #include #include #define M 10 #defi

ID: 3536418 • Letter: P

Question

please consider this code


#include

#include

#include

#include

#define M 10

#define FILLER '.'

int main(void) {

int q, w, new_q, new_w, direction, moves_tried;


/* rows and columns read */


for(q = 0; q < M; q++)

for(w = 0; w < M; w++)

array[q][w] = FILLER;

srand((unsigned) time (NULL));

q = 0;

w = 0;

array[q][w] = character++;

direction = (rand() % 4)+1;

moves_tried = 0;

while (moves_tried < 4 && character <= z="" p="">

{

switch ((direction + moves_tried) % 4)

{

case 0: new_q = q; new_w = w + 1; break;

case 1: new_q = q; new_w = w - 1; break;

case 2: new_q = q + 1; new_w = w; break;

case 3: new_q = q - 1; new_w = w; break;

}

if(new_q >=0 && new_q < M && new_w >= 0 && new_w < M && array[new_q][new_w] == FILLER)

{

q = new_q;

w = new_w;

array[q][w] = character++;

direction = rand() % 4;

moves_tried = 0;

}

else

moves_tried++;

}

for(q = 0; q < M; q++)

{

// display output

for(w = 0; w < M; w++)

printf("%c ", array[q][w]);

printf(" ");


---------------------


the problem is


modify this code to write program should ask the user to enter a seed value

for the random number generation.

Example:

Enter a seed value: 121314

A.........

(remaining program output omitted)

Explanation / Answer

#include

#include

#include

#include

#define M 10

#define FILLER '.'

int main(void) {

int q, w, new_q, new_w, direction, moves_tried;

printf("Please Enter seed value");

scanf("%d",&M);

/* rows and columns read */


for(q = 0; q < M; q++)

for(w = 0; w < M; w++)

array[q][w] = FILLER;

srand((unsigned) time (NULL));

q = 0;

w = 0;

array[q][w] = character++;

direction = (rand() % 4)+1;

moves_tried = 0;

while (moves_tried < 4 && character <= z="" p="">

{

switch ((direction + moves_tried) % 4)

{

case 0: new_q = q; new_w = w + 1; break;

case 1: new_q = q; new_w = w - 1; break;

case 2: new_q = q + 1; new_w = w; break;

case 3: new_q = q - 1; new_w = w; break;

}

if(new_q >=0 && new_q < M && new_w >= 0 && new_w < M && array[new_q][new_w] == FILLER)

{

q = new_q;

w = new_w;

array[q][w] = character++;

direction = rand() % 4;

moves_tried = 0;

}

else

moves_tried++;

}

for(q = 0; q < M; q++)

{

// display output

for(w = 0; w < M; w++)

printf("%c ", array[q][w]);

printf(" ");