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

Write a program in C that generates a list of random numbers greater than or equ

ID: 3923814 • Letter: W

Question

Write a program in C that generates a list of random numbers greater than or equal to 0 and less than 32, stores them in a linked list and prints out the array.

The count of numbers will be passed in on the command line.

Create a thread for initial generation of the numbers and a separate thread for storing them
    in the linked list.

generate all your numbers in thread 1, store the data in an array then create thread 2 and
   have it run through the numbers creating the linked list and storing numbers.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i, count;
time_t t;

if (scanf("Enter the count value : %d",&count) == 1) {
srand((unsigned) time(&t));
for( i = 0 ; i < count ; i++ ){
printf("%d ", rand() % 32);
}

}
else {
printf("Not an integer. ");   
return (EXIT_FAILURE);
}
return 0;
}
/* Algorithm for add a node to the linked list at end*/

Begin:

createSinglyLinkedList (head)
alloc (newNode)
If (newNode == NULL) then
write ('Unable to allocate memory')
End if
Else then
read (data)
newNode.data data
newNode.next NULL
temp head
While (temp.next != NULL) do
temp temp.next
End while
temp.next newNode
End else
End

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