Question
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
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
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