Question: PROGRAM C /* 1. Write a function named sum that accepts an integer n and returns an integer. Declare an integer m an initialize it

PROGRAM C

/* 1. Write a function named sum that accepts an integer n and returns an integer. Declare an integer m an initialize it to zero. This will accumulate the sum. Write a loop to calculate the sum of the first n integers and print each integer to the terminal. Return m to the calling function. Test your code by calling the function from main. After it runs correctly, comment the call in main and start the next problem: 8.

The output should look like below for function call sum(20):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 sum = 210

The first line above should be printed in the sum function's loop. The second line above should be printed in the main function. */

/* 2. Copy the sum function and paste it below, and change the name to sum5. Add code to only calculate the sum of and print integers that are divisible by 5. Test your code by calling the function from main. After it runs correctly, comment the call in main and start the next problem: 9.

The output should look like below for function call sum5(20):

5 10 15 20 sum5 = 50

The first line above should be printed in the sum5 function's loop. The second line above should be printed in the main function. */

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!