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
With thermodynamics, one cannot determine ________.
zloy xaker [14]

Answer:

Option B is correct.

Explanation:

With thermodynamics, one cannot determine the speed of the reaction.

Speed of the reaction is defined as the rate at which one component is changes to another component. With factor cannot be calculated from the thermodynamics branch of engineering.

With thermodynamics we can determine the value of the equilibrium constant,

the extent of a reaction, the temperature at which a reaction will be spontaneous & the direction of a spontaneous reaction. But we cannot determine  the speed of a reaction.

Therefore option B is correct.

4 0
3 years ago
The larger the Bi number, the more accurate the lumped system analysis. a)-True b)- False
mrs_skeptik [129]

Answer:

b). False

Explanation:

Lumped body analysis :

Lumped body analysis states that some bodies during heat transfer process remains uniform at all times. The temperature of these bodies is a function of temperature only. Therefor the heat transfer analysis based on such idea is called lumped body analysis.

                      Biot number is a dimensionless number which governs the heat transfer rate for a lumped body. Biot number is defined as the ratio of the convection transfer at the surface of the body to the conduction inside the body. the temperature difference will be uniform only when the Biot number is nearly equal to zero.  

                      The lumped body analysis assumes that there exists a uniform temperature distribution within the body. This means that the  conduction heat resistance should be zero. Thus the lumped body analysis is exact when biot number is zero.

In general it is assume that for a lumped body analysis, Biot number \leq 0.1

Therefore, the smaller the Biot number, the more exact is the lumped system analysis.

7 0
3 years ago
The permeability coefficient of a type of small gas molecule in a polymer is dependent on absolute temperature according to the
jok3333 [9.3K]

Answer:

Answer for the question is explained in the attachment.

Explanation:

Diffusion flux at 350K for water in polystyrene is equal to

2.8 * 10^-7 .

Download pdf
5 0
3 years ago
Read 2 more answers
An elastic cable is to be designed for bungee jumping from a tower 130 ft high. The specifications call for the cable to be 85 f
azamat

Answer:

<em>a) The spring constant is 50 lb/ft</em>

<em>b) The man is 26.3 ft close to the ground.</em>

<em></em>

Explanation:

Height of tower is 130 ft

Specification calls for a cable of length 85 ft

the maximum this length stretches is 100 ft when subjected to a load of 750 lb

The extension of the cable is calculated from the formula from Hooke's law

F = kx

where F is the load or force on the cable

k is the spring constant of the cable

x is the extension on the cable

a) The extension on the cable is

x = 100 ft - 85 ft = 15 ft

substituting into the formula above, we'll have

750 = k*15

k = 750/15 = <em>50 lb/ft</em>

b) for a 185 lb man, jumping down will give an extension gotten as

F = kx

185 = 50*x

x = 185/50 = 3.7 ft

The total length of the cable will be extended to 100 ft + 3.7 ft = 103.7 ft

closeness to the ground = 130 ft - 103.7 ft =<em> 26.3 ft</em>

3 0
3 years ago
What is the direct current generator​
LUCKY_DIMON [66]

Answer:

A direct-current (DC) generator is a rotating machine that supplies an electrical output with unidirectional voltage and current.

Explanation:

Hope this helps

6 0
2 years ago
Other questions:
  • failure to yield the right-of-way to another vehicle or pedestrian is the primary Collision factor in about 20% of fatal and inj
    8·1 answer
  • A 1-m long, thin symmetric airfoil is placed at a free stream. Calculate the drag force for the wind speed of 150 m/s. Assume th
    7·1 answer
  • Five bolts are used in the connection between the axial member and the support. The ultimate shear strength of the bolts is 280
    9·1 answer
  • What is clearance? What is backlash? What is interference? Explain briefly.
    6·1 answer
  • A mechanism is a device that transmits movement so the output movement is different from the input movement. identify three ways
    5·1 answer
  • the diagram shows an electrical circuit when the switch is open and closed which series of energy transformation occurs when the
    15·1 answer
  • A cylindrical 1045 steel bar is subjected to repeated compression-tension stress cycling along its axis. If the load amplitude i
    10·1 answer
  • What is 3'-9" in feet?
    11·1 answer
  • QUESTION 1
    6·1 answer
  • While servicing a vehicle, you retrieve the diagnostic code P0401, "EGR (exhaust gas recirculatior flow insufficient." Which of
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!