Question

Output each floating-point value with two digits after the decimal point, which can be achieved as...

Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
printf("%0.2lf", yourValue);

(1) Prompt the user to enter five numbers, being five people's weights. Store the numbers in an array of doubles. Output the array's numbers on one line, each number followed by one space. (2 pts)

Ex:

Enter weight 1:
236.0
Enter weight 2:
89.5
Enter weight 3:
142.0
Enter weight 4:
166.3
Enter weight 5:
93.0
You entered: 236.00 89.50 142.00 166.30 93.00

(2) Also output the total weight, by summing the array's elements. (1 pt)

(3) Also output the average of the array's elements. (1 pt)

(4) Also output the max array element. (2 pts)

Ex:

Enter weight 1:
236.0
Enter weight 2:
89.5
Enter weight 3:
142.0
Enter weight 4:
166.3
Enter weight 5:
93.0
You entered: 236.00 89.50 142.00 166.30 93.00 

Total weight: 726.80
Average weight: 145.36
Max weight: 236.00

Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
printf("%0.2lf", yourValue);

C programming

Homework Answers

Answer #1

The required C code is given below in case of any doubts you can ask me in comments and make sure to upvote as it affects my career a lot.

main.c

#include <stdio.h>

int main()
{
double weight[5];
int i = 0;
double total = 0;
double largest = 0;
for( i = 0; i< 5 ; i++)
{
printf("Enter weight %d:\n",(i+1));
scanf("%lf",&weight[i]);
total += weight[i];
if(largest < weight[i])
largest = weight[i];
}
printf("You entered: %.2lf %.2lf %.2lf %.2lf %.2lf\n",weight[0],weight[1],weight[2],weight[3],weight[4]);
printf("Total weight: %.2lf\n",total);
printf("Average weight: %.2lf\n",(total/5));
printf("Max weight: %.2lf\n",largest);
  
return 0;
}
Output Code Screenshot

Output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT