Question: I have written a program that 10 integers (in the interval 1 to 10) and prints them on the screen. The program then asks the

I have written a program that 10 integers (in the interval 1 to 10) and prints them on the screen. The program then asks the user for a number and counts the number of occurrences of this specific number among the 10 randomized numbers and present the answer. The 10 numbers are saved in an array.

My question is: how can I modify the program to print the number that occurs the most frequently and the number that occurs least frequently among the 10 randomized numbers, along with the number of occurrences these numbers occurs with?

My code:

#include #include #define SIZE 10 int CreateGenerator(int* arr) { int i; for (i = 0; i < SIZE; i++) { arr[i] = rand() % 10 + 1; printf("number: %d ", arr[i]); } return arr; } int countElement(int* inputArray, int arraySize, int elementToCount) { int count = 0; for (int i = 0; i < SIZE; i++) { if (elementToCount == inputArray[i]) { count++; } } return count; }

int main() { int arr[SIZE]; int number, choice = 1; while (choice == 1) { CreateGenerator(arr); printf("What to search for: "); scanf_s("%d", &number); int occured = countElement(arr, SIZE, number); printf("The number %d occurs %d times ", number, occured); printf("Do you want to generate a new sequence (1 for yes, 0 for no)? "); scanf_s("%d", &choice); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!