Answer to Question #289014 in C++ for khaled

Question #289014

Creating a recursive function can be accomplished in two steps.

  • Write the base case -- Every recursive function must have a case that returns a value without performing a recursive call. That case is called the base case. A programmer may write that part of the function first, and then test. There may be multiple base cases.
  • Write the recursive case -- The programmer then adds the recursive case to the function. 

The following illustrates a simple function that computes the factorial of N (i.e. N!). The base case is N = 1 or 1! which evaluates to 1. The base case is written as  if (N <= 1) { fact = 1; }. The recursive case is used for N > 1, and written as else { fact = N * NFact( N - 1 ); }.


1
Expert's answer
2022-01-20T01:46:21-0500

#include<iostream>


using namespace std;


int main()

{

int N;

cout << "Please, a number of elements: ";

cin >> N;

int* arr = new int[N];

cout << "Enter elements: ";

for (int i = 0; i < N; i++)

{

cin>> arr[i];

}

cout << "\nThe even numbers are ";

for (int i = 0; i < N; i++)

{

if (arr[i] % 2 == 0)

			cout << arr[i] << " ";

}

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment