Answer:
Following is the program in the C language
#include <stdio.h> // header file
int main() // main function
{
float weight1[10]; // array declaration
float sum=0,max1,t; // variable declaration
for(int k = 0; k < 5; k++) //iterating the loop
{
printf("Enter weight %d: ",k+1);
scanf("%f",&weight1[k]); // Read the array by user
}
printf("\\");
printf("You entered: ");
max1=weight1[0];
for(int k = 0; k < 5 ; k++)
{
sum=sum+weight1[k];
if(max1 < weight1[k]) // check condition for highest element
{
max1=weight1[k];
}
printf("%.2lf ",weight1[k]);
}
t=sum/5.0; // find average
printf("\\Total weight: %.2lf\\",sum); // displat total
printf("Average weight: %.2lf\\",t); // display Average
printf("Max weight: %.2lf\\",max1); // display maximum value
return 0;
}
Output:
Enter weight 1: 1
Enter weight 2: 2
Enter weight 3:3
Enter weight 4:4
Enter weight 5: 5
You entered: 1.00 2.00 3.00 4.00 5.00
Total weight: 15.00
Average weight: 3.00
Max weight: 5.00
Step-by-step explanation:
Following are description of program :
- Declared a array "weight1" of type "float" .
- Declared a variable sum,t max1 of type "float ".
- Iterating the loop for taking the input by the user by using scanf statement .
- Iterating the loop for calculating the maximum value in "max1" variable ,total in "sum" variable .
- In the "t" variable we calculated the average.
- Finally we print the value of the maximum ,average ,total and respective array that are mention in the question .