Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions