Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 %3D 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started