Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming. Please add comments 1. Recursion: Sum of Even numbers in a rang

ID: 3596204 • Letter: C

Question

C++ Programming. Please add comments

1. Recursion: Sum of Even numbers in a range
Write the comments with input, output, description, and test cases for a recursive function that adds up all the even numbers in a range.

% Given a range 1 to 10
>> sumEvenNum(1,10)
ans = 30
>> sumEvenNum(2,5)
ans = 6

2. Recurrence Relations
Write recursive functions with test cases that output the first six terms of the sequence defined by each of these recurrence relations and initial conditions.

Note: If you’re implementing in C++, do not use pow function but create a recursive function raisePow(x,n) that solves x^n.

3. Recursion: Sort Game (One of the reasons why we sort)
Write a recursive function that guesses a number between 0 and x (x being an input number to the function). If you guess too high, it tells you that and continues. If you guess too low, it tells you that and continues. If you guess the number, it tells you how many guesses you took and stops.

4. Write the comments with input, output, and test cases for a recursive function that creates a ”gibberish” language. So if a letter in a word is a vowel, it is replaced with ”ithag”, then the vowel, whereas if the letter is a consonant, it is just included normally.

• For instance, the word ”dog” would be ”dithagog”
• ”math” would be ”mithagath”

(b) (c) (d) an = 3a -i ,a,-1 an = an-l + 2n + 3, ao-4 a," = an-i-an-2-an-3, ao = i, a i = 1, a2 = 2

Explanation / Answer

1)

Input:Start and end (range)

Output: sum of even numbers

Description:

Here the start and end value is passed to the function where the number within the range is checked whether the number is even if so then it is added to the sum value.

program:

#include <iostream>

using namespace std;

int Sumofevennumbers(int start,int end)

{

int sum=0,i;

for(i=start;i<=end;i++)

{

if(i%2==0) //check whether even or not

{

sum=sum+i;

}

  

}

return sum;

}

int main() {

// your code goes here

int s,start,end;

cout<<"Enter the Range";

cin>>start>>end;

s=Sumofevennumbers(start,end); //function call to sum the even numbers

cout<<s; // to print the sum

return 0;

}

Output:

Enter the range: 1 10

30

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote