Create A Structure

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 structurestruct Car{int startKm;int endKm;int litre;};Sample Input:Enter the startKm of car 1: 50Enter the endKm of car 1: 90Enter the fuel used of car 1: 4Enter the startKm of car 2: 50Enter the endKm of car 2: 90Enter the fuel used of car 2: 2
Sample Output:Mileage of audia4:10km/ltMileage of fordfigo:20km/ltMileage of fordfigo is more than audia4

Implementation of the above problem:#includestruct 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;

(adsbygoogle = window.adsbygoogle || []).push({});
ThanksMukesh Rajput