Friday, March 28, 2014

Program to calculate the average consumption of gallons of fuel during given kilometers to save fuel.

#include<stdio.h>
#include<stdlib.h>
void line()
{
int i,j;
printf("\n");
for(i=1;i<=42;i++)
printf("=");
}
void header()
{
printf("\n");
printf("Built and Designed by Arslan Malik\n\n www.CworldbyAS.blogspot.com");
printf("\n");
}
int main()
{
line();
header();
line();

int miles,gallons,average,i,j,sum1,sum2,mpg=miles/gallons;
printf("Enter the Number of Readings : ");
scanf("%d",&j);
for (i=1;i<=j;i++)
{

for(miles=1;miles<=j;miles++)
{
    printf("\nEnter the Number of Miles : ");
scanf("%d",&miles);
sum1=miles+j;
}
}
for(i=1;i<=j;i++)
{

for(gallons=1;gallons<=j;gallons++)
{
    printf("\nEnter the Number of Gallons used : ");
scanf("%d",&gallons);
sum2=gallons+j;

}

}
printf("\nSum of Miles is : %d",sum1);
printf("\nSum of Gallons is : %d ",sum2);
printf("\nMiles covered per gallon : %d",mpg);
printf("\nAverage : %d",(sum1+sum2/j));


return 0;
}

No comments:

Post a Comment