Question

Write a function that takes two ints and returns the average (float) of those two ints....

Write a function that takes two ints and returns the average (float) of those two ints. Include a function prototype. In main, call the function with two int inputs of your choice and print the returned value to the output window. The function should not print, just make the calculation an return the average.

C language not C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

float average(int n1, int n2);

int main() {
   float avg = average(745 , 892);
   
   printf("%.1f",avg);
   
    return 0;
}

float average(int n1, int n2){
   return (n1+n2)/2.0;
}

818.5

Add a comment
Know the answer?
Add Answer to:
Write a function that takes two ints and returns the average (float) of those two ints....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C Write a function that takes two ints and returns the minimum (smallest) of those...

    Using C Write a function that takes two ints and returns the minimum (smallest) of those two ints. Include a function prototype. In main, call the function with two int inputs of your choice and print the returned value to the output window. The function should not print, just return the smallest number (int). If the numbers are the same, the minimum is just the number. Please use notes to explain, thanks!

  • 4. Write a C definition (prototype) for a function called power which takes a float and...

    4. Write a C definition (prototype) for a function called power which takes a float and an integer as inputs, and returns a float as a result. 5. Write the body of the function from (4). This function should raise the first argument to the power of the second, by multiplying it by itself that many times (don’t use the inbuilt pow function, write your own). Do not worry about “special” cases like negative powers. Please do Q.5

  • 4)   Write a function named remove that returns void, takes in a string& called word, and...

    4)   Write a function named remove that returns void, takes in a string& called word, and an int called i that, starting from index 0, removes every ith letter from word by modifying it in place. Include a functional main method to make sure the program works. Programming language is C++, thanks in advance

  • I need this in C++ Write a function using the following structure and prototype. struct Stats...

    I need this in C++ Write a function using the following structure and prototype. struct Stats { float avg; //Average value of an integer array float median; //Median value of an integer array int *mode; //array containing the modes int nModes; //number of modes in the array int maxFreq; //max frequency of modes }; Stats *avgMedMode(int *,int); The function takes in an integer array and the size of the array. Then returns a pointer to a structure containing the average,...

  • Functions can return a string, not just an int or a float. Write a function called...

    Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • write a c++ function, do not #include anything, that returns the max of 6 ints int...

    write a c++ function, do not #include anything, that returns the max of 6 ints int max(int, int, int, int, int, int); allowed to use built in max(int, int) function.

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

  • Language: Python Topic: Try/Except Function name : add_divide Parameters : list of ints, int Returns: float...

    Language: Python Topic: Try/Except Function name : add_divide Parameters : list of ints, int Returns: float Description: Given a list of integers and a number, you want to add the numbers in the list to a total value by iterating through the given list. However, when the index you are at is divisible by the integer passed in, you must instead divide the current total by the element at that index. You must be careful when dividing the total (you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT