Question: 1 / / Ex . 7 . 1 8 : Ex 0 7 _ 1 8 . cpp 2 / / What does this program

1// Ex.7.18: Ex07_18.cpp
2// What does this program do?
3 #include
4 using namespace std;
5
6 int whatIsThis( int [], int ); // function prototype
7
8 int main()
9{
10 const int arraySize =10;
11 int a[ arraySize ]={1,2,3,4,5,6,7,8,9,10};
12
13 int result = whatIsThis( a, arraySize );
14
15 cout << "Result is "<< result << endl;
16}// end main
17
18// What does this function do?
19 int whatIsThis( int b[], int size )
20{
21 if ( size ==1)// base case
22 return b[0];
23 else // recursive step
24 return b[ size -1]+ whatIsThis( b, size -1);
25}// end function whatIsThis

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 Programming Questions!