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
gladu [14]
3 years ago
5

2.31 LAB: Simple statistics Part 1 Given 4 integers, output their product and their average, using integer arithmetic. Ex: If th

e input is: 8 10 5 4 the output is: 1600 6 Note: Integer division discards the fraction. Hence the average of 8 10 5 4 is output as 6, not 6.75. Note: The test cases include four very large input values whose product results in overflow. You do not need to do anything special, but just observe that the output does not represent the correct product (in fact, four positive numbers yield a negative output; wow). Submit the above for grading. Your program will fail the last test cases (which is expected), until you complete part 2 below. Part 2 Also output the product and average, using floating-point arithmetic. Output each floating-point value with three digits after the decimal point, which can be achieved as follows: printf("%0.3lf", yourValue); Ex: If the input is 8 10 5 4, the output is: 1600 6 1600.000 6.750

Engineering
2 answers:
Elden [556K]3 years ago
5 0

Answer:

Explanation:

Note: Integer division discards the fraction. Hence the average of 8, 10, 5, 4 is output as 6, not 6.75.

Note: The test cases include four very large input values whose product results in overflow. You do not need to do anything special, but just observe that the output does not represent the correct product (in fact, four positive numbers yield a negative output; wow).

Submit the above for grading. Your program will fail the last test cases (which is expected), until you complete part 2 below.

Part 2: Also output the product and average, using floating-point arithmetic.

Output each floating-point value with three digits after the decimal point, which can be achieved as follows: System.out.printf("%.3f", yourValue);

Ex: If the input is 8, 10, 5, 4, the output is:

import java.util.Scanner;

public class LabProgram {

 public static void main(String[] args) {

     Scanner scnr = new Scanner(System.in);

     int num1;

     int num2;

     int num3;

     int num4;

       num1 = scnr.nextInt();

       num2 = scnr.nextInt();

       num3 = scnr.nextInt();

       num4 = scnr.nextInt();

       double average_arith = (num1+num2+num3+num4)/4.0;

       double product_arith = num1*num2*num3*num4;

       int result1 = (int) average_arith;

       int result2 = (int) product_arith;

       System.out.printf("%d %d\n",result2,result1);

       System.out.printf("%.3f %.3f\n",product_arith,average_arith);

  }

}

expected output : 1600.000 6.750

kipiarov [429]3 years ago
4 0

Answer:

Complete code with step by step comments for explanation and output results are provided below.

Code with Explanation Part-1:

#include <stdio.h>

int main()

{

// an array of four integers of type int is defined to store the data from the user

   int number[4];

// variables of type int to store the result of product and average of numbers

   int prod, avg;

   printf("Please enter the four integers: ");

// get four integers from the user, %d specifier is used for int    

   scanf("%d %d %d %d",&number[0],&number[1], &number[2],&number[3] );

// calculate the product of numbers by multiplying them together

   prod= number[0]*number[1]*number[2]*number[3];

// calculate the average of numbers by dividing the sum of numbers with total numbers

   avg= (number[0]+number[1]+number[2]+number[3])/4;

// print the product and average of the numbers

   printf("The product of the four numbers is = %d\n",prod);

   printf("The Average of the four numbers is = %d",avg);    

   return 0;

}

Output Part-1:

Please enter the four integers: 8 10 5 4

The product of the four numbers is = 1600

The Average of the four numbers is = 6

As you can see, by using int type we are not getting the exact value of average.

Code with Explanation Part-2:

#include <stdio.h>

int main()

{

// here we just changed the type from int to float

   float number[4];

   float prod, avg;

   printf("Please enter the four integers: ");

//  %f specifier is used for floating point numbers

   scanf("%f %f %f %f",&number[0],&number[1], &number[2],&number[3] );

   prod= number[0]*number[1]*number[2]*number[3];

   avg= (number[0]+number[1]+number[2]+number[3])/4;

// %0.3f is used to show up to 3 decimal digits

   printf("The product of the four numbers is = %0.3f\n",prod);

   printf("The Average of the four numbers is = %0.3f",avg);

   return 0;

}

Output Part-2:

Please enter the four integers: 8 10 5 4

The product of the four numbers is = 1600.000

The Average of the four numbers is = 6.750

As you can see, by using float type we are getting the exact value of average.

You might be interested in
Vital role of maritime english among seaferers
seropon [69]

Answer:

uehgeg7djw7heidiisosowiuisiejei2k

8 0
3 years ago
Paint can shaker mechanisms are common in paint and hardware stores. While they do a good job of mixing the paint, they are also
Ymorist [56]

Answer:

A good design for a portable device to mix paint minimizing the shaking forces and vibrations while still effectively mixing the paint. Is:

The best design is one with centripetal movement. Instead of vertical or horizontal movement. With a container and system of holding structures made of materials that could absorb the vibration effectively.

Explanation:

First of all centripetal movement would be friendlier to our objective as it would not shake the can or the machine itself with disruptive vibrations. Also, we would have to use materials with a good grade of force absorption to eradicate the transmission of the movement to the rest of the structure. Allowing the reduction of the shaking forces while maintaining it effective in the process of mixing.

6 0
3 years ago
Which system of linear inequalities is represented by the graph? y &gt; x – 2 and y x + 1 y x + 1 y &gt; x – 2 and y &lt; x + 1
KatRina [158]

Answer:

The graph representing the linear inequalities is attached below.

Explanation:

The inequalities given are :

y>x-2   and y<x+1

For tables for values of x and y and get coordinates to plot for both equation.

In the first equation;

y>x-2

y=x-2

y-x = -2

The table will be :

x    y

-2  -4

-1    -3

0     -2

1      -1

2      0

The coordinates to plot are : (-2,-4) , (-1,-3), (0,-2), (1,-1) ,(2,0)

Use a dotted line and shade the part right hand side of the line.

Do the same for the second inequality equation and plot then shade the part satisfying the inequality.

The graph attached shows results.

5 0
3 years ago
Read 2 more answers
Immediately remove the machine from service
My name is Ann [436]

Answer:

cellular service/data

Explanation:

Mobile Data and hotspot

3 0
1 year ago
To read signs you need good focal vision
kow [346]

Answer:eyesight

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Classify the terms as related to a thermal system or mechanical system.
    8·1 answer
  • An aquifer has three different formations. Formation A has a thickness of 8.0 m and hydraulic conductivity of 25.0 m/d. Formatio
    9·1 answer
  • How far do you jog each morning? You prefer to jog in different locations each day and do not have a pedometer to measure your d
    14·1 answer
  • A heat recovery device involves transferring energy from the hot flue gases passing through an annular region to pressurized wat
    6·1 answer
  • 5) Initially, the pressure and temperature of steam inside a solid capsule is at 100-pound force per square inch absolute (psia)
    6·1 answer
  • Consider atmospheric air at 20°C and a velocity of 30 m/s flowing over both surfaces of a 1-m-long flat plate that is maintained
    11·1 answer
  • A lighthouse built at sea level is 170ft high from its top , the angle of depression of a buoy is 29 degrees . Find the distance
    10·1 answer
  • What is a network? I'LL MARK BRAINLEST
    12·2 answers
  • Is there anyone who can help me with welding?
    7·1 answer
  • Vivian's Violins has sales of $326,000, contribution margin of $184,000 and fixed costs total $85,000. Vivian's Violins net oper
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!