Professional Documents
Culture Documents
Assignment 1
Instructions:
● You need to submit a word and a pdf file against this assignment with proper name
format (e.g., RegNum_Assignment#1_PostLab_ICP)
● If found plagiarism, straight zero will be marked against assignment.
● Submit Assignment on Due Date. (No Late Submission will be Tolerated)
“Because of the high price of petrol, you are concerned with the fuel consumption of your car. As a
result, you have a record of the kilometers driven and liters used for each tank of petrol you purchase.
Write a program that will display the kilometers driven, liters used, and consumption (in liters/100km)
for each tankful. After processing all the input information, the program should calculate the overall
average consumption.” (Hint: The liters/100km is (Liters/KM driven) x 100)
Sample Output:
Total consumption=0;
Num records=0;
Input liters;
Is
Liters=-1
Input km Driven;
Consumption=(liters/km driven)*100;
Display consumption;
Input liters;
Is Avg
numrecords=0 consumption=0
End
Algorithm:
Algorithm to input the kilometers driven and liters used and compute the consumption for each
record and average consumption for all records entered
Step 1: Declare variables liters, km Driven, consumption, total Consumption, num Records, avg
Consumption of number type
Step 2: Set totalConsumption to 0
Step 3: Set numRecords to 0
Step 4: Input liters
Step 5: While (liters! = -1) // loop that continues until user enters -1 as liters used
do
Increment numRecords by 1
Input kmDriven
Calculate consumption = (liters/kmDriven)*100
{
printf("Enter the liters used(-1 to end):");
scanf("%lf",<);
if(lt==-1)
{
break;
}
printf("Enter the kilometers driven:");
scanf("%lf",&km);
ltpr100=(lt/km)*100;
avg+=ltpr100;
printf("The liters/100km for this tank was %.2lf\n",ltpr100);
cnt++;
}
avg/=cnt;
Screenshots: