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 or equal to the average and fill out the second array with these numbers. You need to design the function.

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=sum/arr_size; //assigning the second array 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

}

int main() { int arr_size; cout<<"Enter the size of array: "; cin>>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);

}

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!