Question: INSTRUCTION : Write the code that would appear in the function body without changing the function header or the behavior of the function. Please use

INSTRUCTION: Write the code that would appear in the function body without changing the function header or the behavior of the function. Please use the same header for all questions.
a) Write the body of the sum function using a single for-loop instead of a while-loop.
b) Write the body sum of the sum function using a single do-while loop instead of a while-loop.
c) Write the body of the sum function using recursion instead of a while-loop.
d) Write the body of the sum function using no loops or recursion.
int sum (int n) { int sum = 0; while (n > 0) { sum = sum + n; --n; } return sum; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
