Write a program in C that generates a list of random numbers

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.

Solution

#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

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.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site