Average consumption bike fuel

SemiColon
By -
0 minute read
2
10.  Write a C program to calculate a bike’s average consumption from the given total 
distance (integer value) traveled (in km) and spent fuel (in liters, float number 
– 2 decimal point). 

Test Data :

Input total distance in km: 350
Input total fuel spent in liters: 5

Expected Output:

Average consumption (km/lt) 70.00

Solution:

#include<stdio.h>
int main()
{
    int km;
    double fuel, avg;

    printf("Input total distance in km: ");
    scanf("%d", &km);
    printf("Input total fuel spent in liters: ");
    scanf("%lf", &fuel);

    avg=km/fuel;
    printf("
Average consumption (km/lt) %.2lf\n", avg);

    return 0;

}


Tags:

Post a Comment

2Comments

  1. Replies
    1. In C programming, the format specifier "%.2lf" is used with the printf or sprintf functions to format and print or store a double floating-point number with two decimal places.

      Delete
Post a Comment