- 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
3 ответов
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?
0
Please give me the program
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.