1. Engineering
  2. Computer Science
  3. lab exercises 1 create a c program named lab1b1cpp which...

Question: lab exercises 1 create a c program named lab1b1cpp which...

Question details

Lab Exercises 1. Create a C++ program named lab1b_1.cpp which completes a function named post_4 such that when given an array of ints, post_4 returns the number of elements from the array that come after the rightmost 4 in the array. The array will contain at least one 4. post_4( {2, 4, 1, 2}, 4 ) returns 2 post_4( {4, 1, 1, 4, 2}, 5 ) returns 1 post_4( {4, 4, 1, 2, 3} , 5) returns 3 post_4( {4} , 1) returns 0 // Precondition: nums contains at least one 4 int post_4(int nums[], int length) { Your main function might look like: #include using namespace std; int post_4(int nums[], int length); int main() { int ary[] = {2, 4, 1, 2}; int count = post_4(ary, 4); cout << "The number of values after the last 4: " << count << endl; return 0; } // define the function here CSS-2A

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution