Write a program to find which car gives the highest mileage. Declare two objects of the car- audia4, fordfigo. Car details need to be displayed to the user.
Create a structure
struct Car
{
int startKm;
int endKm;
int litre;
};
Sample Input:
Enter the startKm of car 1: 50
Enter the endKm of car 1: 90
Enter the fuel used of car 1: 4
Enter the startKm of car 2: 50
Enter the endKm of car 2: 90
Enter the fuel used of car 2: 2
Sample Output:
Mileage of audia4:10km/lt
Mileage of fordfigo:20km/lt
Mileage of fordfigo is more than audia4
Implementation of the above problem:
#include<stdio.h>
struct Car
{
int startKm;
int endKm;
int litre;
};
int main()
{
struct Car c1,c2;
int avg,avg1;
int total,total1;
printf("Enter the startKm of car 1:");
scanf("%d",&c1.startKm);
printf("Enter the endKm of car 1:");
scanf("%d",&c1.endKm);
printf("Enter the fuel used of car 1:");
scanf("%d",&c1.litre);
printf("Enter the startKm of car 2:");
scanf("%d",&c2.startKm);
printf("Enter the endKm of car 2:");
scanf("%d",&c2.endKm);
printf("Enter the fuel used of car 2:");
scanf("%d",&c2.litre);
total=c1.endKm-c1.startKm;
total1=c2.endKm-c2.startKm;
avg=total/c1.litre;
avg1=total1/c2.litre;
printf("Mileage of audia4:%dkm/lt\n",avg);
printf("Mileage of fordfigo:%dkm/lt\n",avg1);
printf("Mileage of fordfigo is more than audia4");
return 0;
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: