Question

*Answer must be in C* Write a function definition of a function named “distance” that has...

*Answer must be in C*

Write a function definition of a function named “distance” that has two float parameters,

the first representing amount of fuel (in gallons) and the second representing the fuel consumption (in miles/gallon).

The function returns the distance, as a float, that could be traveled with the amount of fuel passed and the consumption rate passed to it.

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

float distance(float fuel, float mpg) {
    return mpg * fuel;
}

int main() {
    float fuel, mpg;
    printf("Enter amount of fuel: ");
    scanf("%f", &fuel);
    printf("Enter fuel consumption(mpg): ");
    scanf("%f", &mpg);
    printf("distance travelled is %f\n", distance(fuel, mpg));
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
*Answer must be in C* Write a function definition of a function named “distance” that has...
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
  • Write the definition of a function named timeOnHighway that receives three parameters, all of type double: mileEndingPo...

    Write the definition of a function named timeOnHighway that receives three parameters, all of type double: mileEndingPoint , mileStartingPoint , and speed . The first two parameters indicate the mile markers on an interstate at which a vehicle goes to and starts at; the third parameter indicates the speed of the vehicle in miles per hour. The function returns the number of hours it takes a vehicle to go from the starting mile marker to the ending one. The function...

  • please cleary write How many gallins were consumed by each of the two cars that week....

    please cleary write How many gallins were consumed by each of the two cars that week. first car: second car: A family has two cars. The first car has a fuel efficiency of 40 miles per gallon of gas and the second has a fuel efficiency of 20 miles per gallon of gas. During one particular week, the two cars went a combined total of 1100 miles, for a total gas consumption of 35 gallons. How many gallons were consumed...

  • In Python: Write the definition for a function named avg which accepts two int parameters, and...

    In Python: Write the definition for a function named avg which accepts two int parameters, and returns the average of the two values Write a statement that calls this function to print out the average of values 11 and 25.

  • Write a definition for a class named Book with attributes title, price and author, where author...

    Write a definition for a class named Book with attributes title, price and author, where author is a Contact object and title is a String, and price is a float number. You also need to define the Contact class, which has attributes name and email, where name and email are both String. Instantiate a couple of Book objects that represents books with title, price and author (You can come up with the attributes values for each object) Write a function...

  • C++ LANGUAGE The following formula can be used to determine the distance an object falls in...

    C++ LANGUAGE The following formula can be used to determine the distance an object falls in a specific time period: d = 1 2 g t 2 where d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, the object has been falling. Write a function named fallingDistance that accepts an object's falling time in seconds as an argument. You must define a named constant for g using a meaningful name and...

  • The program we are working on is named code blocks 4. Write a function named findMax...

    The program we are working on is named code blocks 4. Write a function named findMax that has two inte both arguments are equal, return the first. ger parameters and returns the larger of the two. If

  • 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

  • Write a program to compute miles per gallon of a car, over a long trip. The...

    Write a program to compute miles per gallon of a car, over a long trip. The car begins the trip with a full tank, and each fuel stop along the way fills the tank again. You will not do any math, arithmetic, or computations in the main() function. All output will be displayed from the main() function. Start the program by asking the user for the starting odometer reading. All odometer readings will be in whole miles only. The fuel...

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • In the space below, write a C function definition for a function named StrLower, which will...

    In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...

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