Write a C++ programm. Calculate the max value in an integer array (size 100) and how…
- User
Write a C++ programm. Calculate the max value in an integer array (size 100) and how many times it occurs throughout the given array. Use 2 separate non-void functions.
- Assistant
Here's a C++ program that calculates the maximum value in an integer array of size 100 and counts how many times it occurs throughout the given array using two separate non-void functions:
#include<iostream> using namespace std; int findMax(int arr[], int size) { int maxVal = INT_MIN; for (int i = 0; i < size; i++) { if (arr[i] > maxVal) { maxVal = arr[i]; } } return maxVal; } int countOccurrence(int arr[], int size, int target) { int count = 0; for (int i = 0; i < size; i++) { if (arr[i] == target) { count++; } } return count; } int main() { int arr[100]; cout << "Enter 100 integers:" << endl; for (int i = 0; i < 100; i++) { cin >> arr[i]; } int maxVal = findMax(arr, 100); int occurrenceCount = countOccurrence(arr, 100, maxVal); cout << "Maximum value: " << maxVal << endl; cout << "Number of occurrences: " << occurrenceCount << endl; return 0; } - User
Write a C++ programm. Initialize an array with 100 random integers and print it. Pass the array into functions using reference and a global const N = 100. Calculate the max value in the array and how many times it occurs throughout the given array. Use 2 separate non-void functions.
- Assistant