Question

(1) Prompt the user to enter five numbers, being five peoples weights. Store the numbers in an array of doubles. Output the arrays numbers on one line, each number followed by one space. (2 pts) Ex: Enter weight 1: 236 Enter weight 2: 89.5 Enter weight 3: 142 Enter weight 4: 166.3 Enter weight 5: 93 You entered 236.000000 89.500000 142.000000 166.300000 93.000000 (2) Also output the total weight, by summing the arrays elements. (1 pt) (3) Also output the average of the arrays elements. (1 pt) (4) Also output the max array element. (2 pts) Remaining 4 points will consist of: formatting 2pts and comments 2pts Ex: Enter weight 1: 236 Enter weight 2: 89.5 Enter weight 3: 142 Enter weight 4: 166.3 Enter weight 5: 93 You entered: 236.000000 89.500000 142.000000 166.300000 93.000000 Total weight: 726.800000 Average weight: 145.360000 Max weight: 236.000000

Need a basic program in C using the instructions above. Thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <stdio.h>

int main(void) {
   // your code goes here
  
   //create a double array with name weight and size 5
  
   double weight[5];
  
   //create a variable sum that stores the value of the sum of weights
   //initialise it with 0
  
   double sum = 0;
  
   //create a variable to store maximum value of weight
   //initialise it with -1
  
   double max = -1;
  
  
   for(int i=0;i<5;i++){
      
       //taking the input
      
       printf("Enter weight %d: ",i+1);
       scanf("%lf",&weight[i]);
       printf("\n");
      
       //updating the sum variable or adding current weight to previous sum
       sum += weight[i];
      
       //checking if current weight is greater than max
       //if it's greater put value of current weight in max
      
       if( weight[i] > max ){
           max = weight[i];
       }
   }
  
   //printing the weights in single line
  
   printf("\nYou entered: ");
      
   for(int i=0;i<5;i++){
       printf("%lf ",weight[i]);
   }
  
   printf("\n");
  
   //printing the total weight
  
   printf("Total weight: %lf\n",sum);
  
   //average weight = total weight / number of weights
  
   double average_weight = sum / 5 ;
   printf("Average weight: %lf\n",average_weight);
  
   //printing the maximum weight
  
   printf("Max weight: %lf",max);
  
   return 0;
}

Example Output:

Enter weight 1: 236
Enter weight 2: 89.5
Enter weight 3: 142
Enter weight 4: 166.3
Enter weight 5: 93

You entered: 236.000000 89.500000 142.000000 166.300000 93.000000
Total weight: 726.800000
Average weight: 145.360000
Max weight: 236.000000

Add a comment
Know the answer?
Add Answer to:
Need a basic program in C using the instructions above. Thanks. (1) Prompt the user to...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 14.5 Prog 5: People's weights (arrays) JAVA (1) Prompt the user to enter five numbers, being...

    14.5 Prog 5: People's weights (arrays) JAVA (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.0 89.5 142.0 166.3 93.0 (2) Also output the total weight, by summing the array's...

  • 5.18 Ch 5 Warm up: People's weights (Vectors) (C++) (1) Prompt the user to enter five...

    5.18 Ch 5 Warm up: People's weights (Vectors) (C++) (1) Prompt the user to enter five numbers, being five people's weights. Store the numbers in a vector of doubles. Output the vector'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 89.5 142 166.3 93 (2) Also output the total weight, by summing...

  • 5.23 LAB: Warm up: People's weights (1) Prompt the user to enter five numbers, being five...

    5.23 LAB: Warm up: People's weights (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.0 89.5 142.0 166.3 93.0 (2) Also output the total weight, by summing the array's elements....

  • Hi, I need some help with the following question. I need the answer in Python please....

    Hi, I need some help with the following question. I need the answer in Python please. 10.23 LAB: Warm up: People's weights (Lists) (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts) Ex: Enter weight 1: 236.0 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3] (2) Output the average of the list's elements...

  • Hello, can someone please help me correct this code? I greatly appreciate it. 7.16 Ch 7...

    Hello, can someone please help me correct this code? I greatly appreciate it. 7.16 Ch 7 Warm up: People's weights (Lists) (Python 3) (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts) Ex: Enter weight 1: 236.0 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3] (2) Output the average of the list's elements...

  • ZYBOOKS LAB: 10.23.1 Hello, I'm trying to solve this problem with creating a program code in...

    ZYBOOKS LAB: 10.23.1 Hello, I'm trying to solve this problem with creating a program code in Python about People's Weights. Here is the question: 10.23 LAB: Warm up: People's weights (Lists) (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts) Ex: Enter weight 1: 236.0 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3]...

  • 2. Write a program that reads N integer numbers of array from the user and then...

    2. Write a program that reads N integer numbers of array from the user and then displays the sum, max number and the numbers of the array use four subroutines ( Read_Array(), Calculate_Sum(), Find_Max() and Display_Array()). Here is sample output Please enter number of elements: 4 Please enter the required numbers: 50 100 150 20 The entered numbers are: 50 100 150 20 Sum is : 320 Max is 150 by Mpsi ,sum and max to call subroutine and retrieve...

  • 6.17.1 Lab #5 - Chapter 6 Text analyzer & modifier (C) (1) Prompt the user to...

    6.17.1 Lab #5 - Chapter 6 Text analyzer & modifier (C) (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. (2) Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. We encourage you to use a for loop in this...

  • 1. Write a program that reads in two arrays (a1 and a2) of numbers and creates...

    1. Write a program that reads in two arrays (a1 and a2) of numbers and creates a new array (a3) of numbers such that the new array contains all the unique numbers of a1 and a2. Assume the input array elements are unique elements. In the main function, ask the user to enter the length of each array, declare and reads in the numbers for each array, and calculate and display the output array. Example input/output #1: Enter the length...

  • 6.6 Warm up: Parsing strings (Python 3) (1) Prompt the user for a string that contains...

    6.6 Warm up: Parsing strings (Python 3) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT