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
yaroslaw [1]
4 years ago
11

4.16 LAB: Varied amount of input data Statistics are often calculated with varying amounts of input data. Write a program that t

akes any number of non-negative integers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: If the input is: 15 20 0 5 -1 the output is: 10 20 You can assume that at least one non-negative integer is input. 254058.1561406

Computers and Technology
1 answer:
Brums [2.3K]4 years ago
4 0

Answer:

Here is the C program. Let me know if you want the program in some other programming language.

#include <stdio.h>   //to use input output functions

int main() {   //start of main function

int num;   // to store input numbers

int sum = 0;  //to store the sum of numbers

scanf("%d", &num);   //reads the numbers from user

int count = 0;   //to count the total numbers entered by user

int max = 0;   //to store the maximum of numbers

while(num >= 0)  {  //continues to execute until user enters negative number

sum+=num;   //adds the numbers

scanf("%d", &num);   //reads the numbers from user

count++;   //counts the numbers entered

if(num>=max){    //if number is greater than numbers stored in max

 max = num;   }   }  //assigns that maximum number to max

   printf("%d %d", sum/count,max);  }  //displays the average of numbers and maximum of numbers

Explanation:

I will explain the program with an example. Lets say the first number input by user is 15. Then the loop works as follows:

At first iteration:

num >= 0 is true because 15 is greater than 0 so program moves to the body of loop

sum+=num; becomes:

sum = sum + num

sum = 0 + 15

sum = 15

count++; becomes:

count = count + 1

count = 0 + 1

count = 1

if(num>=max) means if(15>=0) this is true so

 max = num;  this becomes:

max = 15

Lets say the next value entered by user is 20. It is stored in num variable

At second iteration:

num >= 0 is true because 20 is greater than 0 so program moves to the body of loop

sum+=num; becomes:

sum = sum + num

sum = 15 + 20

sum = 35

count++; becomes:

count = count + 1

count = 1 + 1

count = 2

if(num>=max) means if(20>=15) this is true so

 max = num;  this becomes:

max = 20

Lets say the next value entered by user is 0. It is stored in num variable

At third iteration:

num >= 0 is true because 0 is equal to 0 so program moves to the body of loop

sum+=num; becomes:

sum = 35 + num

sum = 35 + 0

sum = 35

count++; becomes:

count = count + 1

count = 2 + 1

count = 3

if(num>=max) means if(0>=20) this is false so

 max = num;  this remains:

max = 20

Lets say the next value entered by user is 5. It is stored in num variable

At fourth iteration:

num >= 0 is true because 5 is greater than 0 so program moves to the body of loop

sum+=num; becomes:

sum = 35 + 5

sum = 35 + 5

sum = 40

count++; becomes:

count = count + 1

count = 3 + 1

count = 4

if(num>=max) means if(5>=20) this is false so

 max = num;  this remains:

max = 20

Lets say the next value entered by user is -1. It is stored in num variable

Now the loop breaks because num >= 0 is false because -1 is less than 0 so program moves to the statement:

printf("%d %d", sum/count,max);

This has two parts to print on output screen:

sum/count which is 40/4 = 10

max which is 20

So the output of the entire program is:

10  20

The screenshot of program along with its output is attached.

You might be interested in
What does Intel mean in this phrase(collect all intel).
aksik [14]
<span>It's short for "intelligence". The phrase means 'collect all information'.</span>
6 0
3 years ago
Read 2 more answers
Using the Sakila database, create a query that displays the film title, description, as well the actor first and last name for a
Alex787 [66]

Answer:

Select title, description , first_name, last_name from film inner join film_actor on film.film_id = film_actor.film_id inner join actor on film_actor.actor_id = actor.actor_id where title LIKE 'zo%';

Explanation:

  • The INNER JOIN keyword selects records that have matching values in both tables.
  • The WHERE clause is used to filter records.
  • The WHERE clause is used to extract only those records that fulfill a specified condition.
7 0
3 years ago
What do work places allow a company to do
anygoal [31]
D. They provide a platform for collaboration
8 0
3 years ago
The design strategy that starts with a global view of the entire problem and breaks the problem down into smaller, more manageab
In-s [12.5K]

Answer:

Top down design

Explanation:

Top-down design is an approach that is used to break down the problem into the smaller subpart so that it can be manageable into more clear form.

C programming is the example of a top-down approach while C++ is the example of the bottom-up approach.

The advantages of the top-down design approach are:

1) easy to manage

2) easy to find the error

3) easy to debug

4 0
3 years ago
When a user attempts to visit an internet-based web server, what is the default action of the windows firewall?
Kamila [148]
Google chrome and internet explore
7 0
3 years ago
Other questions:
  • On computer X, a nonpipelined instruction execution would require 12 ns. A pipelined implementation uses 6 equal-length stages o
    9·1 answer
  • Given a String variable response that has already been declared, write some code that repeatedly reads a value from standard inp
    10·1 answer
  • Which term refers to the blank areas surrounding a document page? *
    15·1 answer
  • Your windows system is used by several people, so you want increase security by requiring users to create passwords that are at
    9·1 answer
  • How many times do you return after the dateline ?
    12·1 answer
  • Heather writes an essay for language arts and receives a poor grade. To figure out why she gets a poor grade, Heather looks at t
    14·2 answers
  • A photographer stores digital photographs on her computer. In this case the photographs are considered the data. Each photograph
    6·1 answer
  • Which is the first computer brought in nepal for the census of 2028 B.S​
    6·1 answer
  • Web résumés allow you to include extra graphics and images that you would not include in a traditional résumé. please select the
    13·1 answer
  • You defined a shoe data type and created an instance.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!