write a C program that takes a floating-point value from the command line. This value is interpreted to be a fuel consumption reading in Miles/Gallon. The program returns the fuel consumption in Liters per 100 Kilometer.
The prototype declaration of the function implementing this looks like this:
float mpg_to_lp100k(float mpg);
Solution:
#include<stdio.h>
#include<stdlib.h>
float mpg_to_lp100k(float mpg)
{
float ans=(1.60934/3.78541)*mpg;
float result=(1/ans)*100.00;
return result;
}
int main(int argc,char *argv[])
{
float mpg,result;
mpg=atof(argv[1]);
result=mpg_to_lp100k(mpg);
printf("The fuel consumption in Litres per 100
Kilometers: %f\n",result);
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.