Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899