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

Write a recursive function which returns the sum of all the even integers from 2

ID: 3660407 • Letter: W

Question

Write a recursive function which returns the sum of all the even integers from 2 to n where n is the value we pass the function. YOUR FUNCTION MUST BE RECURSIVE to get credit for it. Prototype: int even_sum(int n); Write this in C not C++ Write a main function which gets the input n from a file datause.dat and Prints to an output file dataout.out: An echo of the input The sum of all the even numbers from 2 to n is answer. (where n is the input and answer is what the function should have returned). Input File datause.dat just has a 12 i.e. 12 Output file dataout.out has the following: The integer input is 12. The sum of all the even numbers from 2 to 12 is 156.

Explanation / Answer

int sumEvensRecursively(int no1, int no2) { no1=5; no2=20; if (no1 % 2 == 1) { return sumEvensRecursively(no1+ 1, no2); } return no1+ sumEvensRecursively(no1+ 2, no2); }

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