Solve of URI 1017 (Fuel Spent) in C & C++
How to solve:1. In this problem, we need to calculate total fuel spent in a trip.
2. We take two integer inputs, first for total time spent on the trip and second is average speed of the car during the trip.
3. The Car consumes 1 liter fuel to go 12 kilometer. That means, it does 12 km/L.
4. To calculate spent amount of fuel, we need to multiply time with speed and divide by 12.0
5. Finally print the fuel. 3 digits must be printed after decimal point.
See sample input and output for better understanding with printing output.
Go through problem description and see my solution for clear concept. Thanks. :)
Solution in C:
//URI online judge 1017 solution in C
//This solution is made by Mehedi Hasan Kajol
#include<stdio.h>
int main(void){
double time, speed, fuel;
scanf(" %lf %lf ", &time, &speed);
fuel= (time*speed) / 12.0; // Calculating total amount of fuel spent during trip.
printf("%.3lf\n", fuel);
return 0;
}
Solution in C++:
//URI online judge 1017 solution in C++
//This solution is made by Mehedi Hasan Kajol
#include<iostream>
using namespace std;
int main(void){
double time, speed, fuel;
cin >> time >> speed;
fuel= (time*speed) / 12.0; // Calculating total amount of fuel spent during trip.
printf("%.3lf\n", fuel); // Using printf() for precision.
return 0;
}