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
Convert the following numbers. (Please show all steps; no marks will be awarded if no steps are shown) [1.5 x 4 = 6 marks]
katen-ka-za [31]

Answer:

i. 10210212

ii. 100 101 001 in BASE 2

iii. 46.4631

iv. 12.453125

Explanation:

i. Converting to base 10 we get

=  10 x 162 + 13 x 161 + 9 x 160 = 2777

Converting to base 10 we get  =

2777/3 = 925 with remainder 2

925/3 = 308 with remainder 1

308/3 = 102 with remainder 2

102/3 = 34 with remainder 0

34/3 = 11 with remainder 1

11/3 = 3 with remainder 2

3/3 = 1 with remainder 0

1/3 = 0 with remainder 1

Hence the Answer is 10210212

ii. = Octal is taken in pair of 3 bits , Writing binary of each number in 3 bits we get  = 100 101 001 in BASE 2

iii. = 1 x 52 + 2 x 51 + 3 x 50 + 3 x 5-1   = 38.6 in decimal

Converting to Octal we get

38 /8 = 4 with remainder 6

4 /8 = 0 with remainder 4

.6 x 8 =  4.8

.8 x 8 = 6.4

46.4631

iv. = 1x 81 + 4 x 80 + 3 x 8-1 + 5 x 8-2   = 12.453125

Check here for Free courses about IT and Management www.eacademy.lk

4 0
3 years ago
Steve is creating a document with proper nouns, which Word continues to identify as being misspelled.
mash [69]

Answer:

it's D. B and C are correct.

Explanation:

The options are:

A. Skip the Spell Checker.

B. Right-click the noun and choose to Ignore All.

C. Right-click and Add to the dictionary.

D. B and C are correct.

You can either right-click the noun and choose to Ignore all. or you can Right-click and add to the dictionary. And this is because you are correct this time, as a proper noun can have misspelled type of spelling. And this is because it is some other language word, and that's why.

6 0
3 years ago
Read 2 more answers
What permanent magnets of a motor are replaced with more powerful ones, what effect do you think this would have on motor rotati
Marat540 [252]
When permanent magnets of a motor are replaced with more powerful ones, the motor rotation will increase. This is because there is more electricity being generated.
7 0
3 years ago
Read 2 more answers
WHAT DO YOU KNOW?<br> Why would you want to change your Table<br> Properties?
joja [24]

read the slides ;  Table Properties are the way the table appears or looks.

6 0
3 years ago
Printers produce _____ output. Displays produce _____ output. A _____ is an audio output device that converts text to speech. Ma
sesenic [268]

Answer:

"Hard copy", "Soft copy", "voice synthesizer", "flat panel", "projector".

Explanation:

  1. The above-defined words will fill the above blanks. Then the above sentence above below meanings:-
  2. The hard copy is ab printed form of soft copy which is generated by the printer device.
  3. The soft copy is displayed on the monitor screen.
  4. The voice synthesizer is used to convert the text onto a speech.
  5. The flat-panel device has a low volume and weight. There is much display which is in this type.
  6. The projector is used to display on the wall.
8 0
3 years ago
Other questions:
  • _____ is a method of delivering software, in which a vendor hosts the applications, and customers access these applications over
    10·1 answer
  • Can some one please help The term career is usually applied to a what PLEASEEEEEEEEEEEE HEEEEELLLLLPPPPP MEEEEEE
    7·1 answer
  • What are the elements of an autobiographical narrative similar to those of a short story?
    7·1 answer
  • ______________ is only one of the marketing mix tools that acompany uses to achieve its marketing objectives.
    7·1 answer
  • Identifies the row and column that forms the cell
    11·1 answer
  • Use of multimedia in business sector...​?
    5·1 answer
  • Piers wants to take a course on XML. He is a certified web designer, but he has not used XML before. How can he use XML to impro
    8·1 answer
  • if a second system failure occurs while the first recovery is in progress, what needs tobe done after the system recovers for th
    11·1 answer
  • What are the steps to customize a slide show?
    10·2 answers
  • Whose work is responsible for the invention of the air bag? Scientist, Engineers or both?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!