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

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

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