Question: Write a C program to perform some simple math functions. 1. Write a main function. The main function should ask a user for a positive

Write a C program to perform some simple math functions.

1. Write a main function. The main function should ask a user for a positive integer and pass it to the two functions described below. The main function should print the values returned from the two functions as shown below.

2. Write a function called sum() to calculate the sum of the first n integers. The function should accept integer n as an argument and return the integer sum. If n = 5, the function should return 15 (1+2+3+4+5=15). Call this function from main and print the returned value to screen. The output should look like:

The sum of the first 5 integers is 15.

3. Write a function called avg() to calculate the average of the first n integers. It should call the sum function to get the sum and divide it by n. The function should accept integer n and return the average as a double. Remember to cast or use a floating point number in the calculation to make the average a float. Call the avg function from main and print the returned value to screen. The output should look like:

The average of the first 5 integers is 3.0.

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!