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("
return 0;
}
Why add 2f?
ReplyDeleteIn 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