Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions

Question

What is the role of the Joint Commission in health care?

Answered: 1 week ago