- 2

Write a C program to view prime number frequency from user input queue

We have to write a program which will take the queue inputs from user and make it a queue then give prime number frequency

12th Feb 2022, 4:17 AM
Kamalesh Ray
3 Respuestas
0
get input from user parse prime numbers from users input store prime numbers in FIFO order print or return prime numbers array What part are you having difficulties with?
12th Feb 2022, 12:58 PM
William Owens
William Owens - avatar
0
Please give me the program
12th Feb 2022, 12:59 PM
Kamalesh Ray
0
Kalmalesh Ray -- I wont write the program for you without you attempting first, but to get you started here are some bits you can use to put something together. A function to determine prime: int test_for_prime(int some_number){ // Going to loop through all numbers, can be slow if we are testing large numbers for (int i = 2; i <= some_number/2; i++){ if(some_number % i == 0){ return 1; } } return 0; } A way you can create an array of 5 numbers from the user: int main (void) { int num_list[5]; int is_num; for(int i = 0; i < 5; i++) { printf("Please enter number %i of the list: ", (i + 1)); do { is_num = scanf(" %d", &num_list[i]); while(getchar() != '\n'); } while (is_num != 1); } puts("\nYou entered the following numbers:"); for(int i = 0; i < 5; i++) { printf("%i: %i\n", (i + 1), num_list[i]); } } Try to put something together. Would be great to help you out with this.
12th Feb 2022, 6:26 PM
William Owens
William Owens - avatar