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]
4 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]4 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]4 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
The forming section of a plastics plant puts out a continuous sheet of plastic that is 1.2 m wide and 2 mm thick at a rate of 15
KATRIN_1 [288]

Answer:

attached below

Explanation:

7 0
3 years ago
PLS HELP ME
Oksana_A [137]

Answer:

The Euler buckling load of a 160-cm-long column will be 1.33 times the Euler buckling load of an equivalent 120-cm-long column.

Explanation:

160 - 120 = 40

120 = 100

40 = X

40 x 100 / 120 = X

4000 / 120 = X

33.333 = X

120 = 100

160 = X

160 x 100 /120 = X

16000 / 120 = X

133.333 = X

4 0
3 years ago
A large retirement village has a total retail employment of 120. All 1600 of the households in this village consist of two nonwo
polet [3.4K]

Answer:

See explaination

Explanation:

Please kindly check attachment for the step by step solution of the given problem.

5 0
4 years ago
Plz solve the problem
julsineya [31]
I attached a photo that explains and gives the answer to your questions. Had to add a border because the whole picture didn’t fit.

6 0
3 years ago
It has a piece of 1045 steel with the following dimensions, length of 80 cm, width of 30 cm, and a height of 15 cm. In this piec
Serggg [28]

Answer:

material remove in 3 min is 16790.4 mm³/s

Explanation:

given data

length L = 80 cm = 800 mm

width W = 30 cm

height H = 15 cm

make grove length = 80 cm

width = 8 cm

depth = 10 cm

mill toll diameter = 4 mm

axial cutting depth = 20 mm

to find out

How much material removed in 3 minutes

solution

first we find time taken for length of advance that is

time = \frac{length}{advance}

here advance is given as 0.001166 mts / sec

so  time = \frac{800}}{0.001166*1000}

time = 686.106 seconds

now we find material remove rate that is

remove rate = mill toll rate × axial cutting depth × advance

remove rate = 4 × 20×0.001166 ×1000

remove rate = 93.28 mm³/s

so

material remove in 3 minute = 3 × 60 = 180 sec

so material remove in 3 min = 180 × 93.28

material remove in 3 min is 16790.4 mm³/s

7 0
3 years ago
Other questions:
  • For the following gear train, if the blue gear is moving at 50 rpm, what are the speeds of the other gears?
    14·1 answer
  • At a 4 percent annual growth rate in GDP per capita, it will take
    15·1 answer
  • Looking at the response vehicles (pictured above), explain two options you have in order to abide by the Move
    8·1 answer
  • The solid cylinders AB and BC are bonded together at B and are attached to fixed supports at A and C. The modulus of rigidity is
    6·1 answer
  • Need answers for these please ​
    15·1 answer
  • Which engineers are requried to have a PE (professional engineer) license?
    13·2 answers
  • A triangular roadside channel is poorly lined with riprap. The channel has side slopes of 2:1 (H:V) and longitudinal slope of 2.
    9·1 answer
  • 10. To cut 1/4" (6 mm) thick mild steel at a rate of 40 inches per minute, the current would be set to
    7·1 answer
  • What effect will increasing numbers of high-profile green building projects likely have on thinking about building?
    5·1 answer
  • Match the use of the magnetic field to its respective description.​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!