1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
DanielleElmas [232]
3 years ago
11

Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative intege

rs as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is 15 20 0 5 -1, the output is:
Computers and Technology
1 answer:
olga55 [171]3 years ago
6 0

Answer:

I am writing the code in C++. Let me know if your want the program in some other programming language.

#include <iostream> // used to invoke input output functions

using namespace std; // used to identify objects like cout cin etc

int main() //start of the main function of the program

{  int number; // integer type variable storing numbers

  cin>>number; // reads numbers that user inputs

       int count = 0; // counts the total numbers entered

       int maximum = 0; // stores maximum number

       int sum = 0; // stores the total sum of numbers

       int average;  // stores average of the numbers

while (number >= 0) // loop checks if the number enters is greater than 0

   {count++; // increments value of count by 1

     sum = sum+number; // stores addition of each number with total

     maximum =  std::max(maximum, number);

// function to find the maximum of the input numbers

     cin>>number;  // keeps reading the entered numbers    }

  if (count == 0) // if value of count is 0

     { average = 0; } // value of average is 0

  else

    {average = sum/count;} // formula to calculate average

      cout<<average; // displays average of numbers

      cout<<" "; //space between average and maximum numbers

      cout<<maximum; } // displays maximum number

Explanation:

The while loop checks the condition that if the integer type number entered by the users are greater than 0. This means it checks that the numbers should be non- negative.

If the while condition is true then the program control enters the body of the loop.

In the first iteration the value of count is incremented by 1. The current value of count was 0 which now becomes 1. The sum variable stores the sum of the entered number and value in sum variable. The current value of sum is 0. This will be added to the value of number. Next the max function is used to find the maximum of the input numbers. It finds the maximum value between each input number and the current value of maximum. cin will keep reading input numbers as entered by the user and stores it in number variable.

The loop will break once the user enters a negative number.

Now the if condition checks if the value of count is equal to 0. This means it checks if there is no number entered. If its true then the value of average will be 0 and if it is false then the average is calculated by dividing the total sum of input numbers (stored in sum variable) with the total numbers entered by user (stores in count variable)

Lastly the values of maximum and average variables are displayed in the output.

You might be interested in
Anyone play Ro-blox ? without the -
Olin [163]
I do! I know it says high school but I lied :)
6 0
3 years ago
Read 2 more answers
viết phương trình nhập vào bàn phím một dãy số nguyên a1,a2 ....ăn gồm n phần tử nguyên hãy đếm xem trong dãy a có bao nhiêu phầ
Alina [70]

Answer:

Wala ko ka sabot ana oy sorry

5 0
3 years ago
Read 2 more answers
Use the nutrition label to determine how many calories would be consumed by drinking 1 liter of Mountain Dew.
Rus_ich [418]
1 liter of mountain dew is 170 calories
4 0
3 years ago
Read 2 more answers
You have one address, 196.172.128.0 and you want to subnet that address. You want 10 subnets. 1. What class is this address
Korvikt [17]

Answer:

This address is by default a class c network

Explanation:

This IP address in this question is a class c network because it has 196 as its first octet. A class c network is one which has its first octet to be between 192 and 223. the class c network begins with a 110 binary.  If ip is between 192 to 223 it belongs to this class. These first 3 octets are the representation of the network number in the address. Class c's were made to support small networks initially.

8 0
3 years ago
To deny traffic destined to a specific tcp port you will need to apply a __________ access control list.
Fiesta28 [93]
The correct answer for the fill-in-the-blank is [user]3
4 0
4 years ago
Other questions:
  • A/An is a series of instructions or commands that a computer follows; used to create software
    10·2 answers
  • Assume you have written a method with the header num mymethod(string name, string code). the method's type is
    5·1 answer
  • Technology can help governments handle economic emergencies, such as the reliance on automation. Crop and resource shortages. Th
    15·2 answers
  • You have an interface on a router with the IP address of 192.168.192.10 /29. What is the broadcast address the hosts will use on
    15·1 answer
  • The GeForce GTX 1060 graphics card requires 120 W of power. You plan to install it in a PCIe 3.0 ×16 slot. Will you need to also
    13·1 answer
  • Any websites online to make $50 daily?​
    11·1 answer
  • Follow me on insta Aaftabkhan_7​
    13·2 answers
  • Which word or phrase refers to an increasingly common method of computing and storing files?
    15·2 answers
  • Is jesus dead or alive
    11·1 answer
  • Get ready to be the Quizmaster! You are going to design your own Python game show in the style of a quiz.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!