0% found this document useful (0 votes)
17 views

Zoo

Uploaded by

Liya Wilson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Zoo

Uploaded by

Liya Wilson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
int main()
{
struct information
{
char name[20];
float grass;
float water;
};
struct information details[5];
int i;
for(i=0;i<5;i++)
{
printf("\nEnter the name of the animal %d:",i+1);
scanf("%s",details[i].name);

printf("Enter the weight of grass it eats per day:");


scanf("%f",&details[i].grass);
printf("Enter the litre of water it drinks per day:");
scanf("%f",&details[i].water);
}
float sum_g=0;
float sum_w=0;
float avg;
int max=0,j=0;

for(i=0;i<5;i++)
{
sum_g=details[i].grass+sum_g;
sum_w=details[i].water+sum_w;
avg=(float)sum_w/5;
if (max<details[i].grass)
{
max=details[i].grass;
j=i;
}
}
printf("\nTotal amount of grass needed per day=%.2f",sum_g);
printf("\nThe animal that consumes maximum amount of grass every day is
'%s'",details[j].name);
printf("\nThe average water consumed per day by the animals=%.2f",avg);
for (i=0;i<5;i++)
{

if(avg<details[i].water)
printf("\n'%s' consumes more water than the average water consumed by all the animals
together",details[i].name);
}
return 0;
}

You might also like