Algorithm
Fuel Spent
Adapted by Neilor Tonin, URI Brazil
Little John wants to calculate and show the amount of spent fuel liters on a trip, using a car that does 12 Km/L. For this, he would like you to help him through a simple program. To perform the calculation, you have to read spent time (in hours) and the same average speed (km/h). In this way, you can get distance and then, calculate how many liters would be needed. Show the value with three decimal places after the point.
Input
The input file contains two integers. The first one is the spent time in the trip (in hours). The second one is the average speed during the trip (in Km/h).
Output
Print how many liters would be needed to do this trip, with three digits after the decimal point.
Input Sample | Output Sample |
10 |
70.833 |
2 |
15.333 |
22 |
122.833 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
double a, b, r;
scanf("%lf %lf", &a, &b);
r = (a * b)/12;
printf("%.3lf\n", r);
return 0;
}
Copy The Code &
Try With Live Editor
Input
85
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int a, b;
cin >> a;
cin >> b;
float f = (a*b)/12.0;
printf("%.3f\n", f);
return 0;
}
Copy The Code &
Try With Live Editor
Input
92
Output
#3 Code Example with Java Programming
Code -
Java Programming
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
double a, b, r;
Scanner sc = new Scanner(System.in);
a = sc.nextDouble();
b = sc.nextDouble();
r = (a * b)/12;
System.out.printf("%.3f\n", r);
}
}
Copy The Code &
Try With Live Editor
Input
67
Output