Question
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. THE FUNCTION SHOULD FIND ALL NUMBERS IN THE ARRAY THAT ARE GREATER THAN OR EQUAL TO THE AVERAGE. You need to design the function. so the output code should be:
(show contents of 1st array)
The numbers that are greater than the average of the first array are: (the numbers)
so if the array is 1 2 3 4 5 . The numbers outputted should be 3 4 and 5 because 15/5=3 and 3 4 and are greater than and equal to 3.
I tried this code but the errors returned were: expression must have a constant value #include using namespace std; void fillArray(int arr1[],int arr2[],int arr_size) { int cnt=0; double avg,sum; for(int i=0;i=avg)//condition to check average { arr2[cnt]=arr1[i]; //assigning value to array 2 cnt++; } } //printing seond array cout<<"Second array is: "; for(int i=0;i>arr_size; int arr1[arr_size],arr2[arr_size]; cout<<"Enter the element: "; for(int i=0;i>arr1[i]; } fillArray(arr1,arr2,arr_size); }
also this code is incomplete:
#include
// function declaration void fun(int arr1[], int arr2[], int size){
cout<<"Content of 1st array: "< // taking input for 2nd array from user cout<<" Enter "< cout<<" Content of 2st array: "< int main(){ // declaring two array of size 6 and initializing first array with some value int arr1[] = {1,2,3,4,5,6}; int arr2[6]; // calling function fun(arr1, arr2, 6); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started