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

Next, write another function, iterative_compute_sum, that also takes one integer

ID: 665482 • Letter: N

Question

Next, write another function, iterative_compute_sum, that also takes one integer argument and returns the sum of the first n integers. This function, however, does not use a recursive method but will instead compute the sum using a while loop and then returning the answer.

The program you turn in should have the following main program but should work for any values, not just 10:

int main(int argc, char* argv[])

{

printf("%d ", recursive_compute_sum(10)); printf("%d ", iterative_compute_sum(10));

return 0;

}

Explanation / Answer

int iterative_compute_sum(int n)
{
    int sumi=0,current=1;
    while(current<=n)
    {
        sumi+=current;
        current++;
    }
    return sumi;
}

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