answer.
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]
2 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]2 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]2 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
An art collector is bidding on a statue that would complete a collection he is trying to assemble. The statue is being sold in a
serious [3.7K]

Answer: Equal to his willingness to pay for the statue.

Explanation:Vickrey (sealed second-price) auction is a type of seal bidding system named after a Nobel price winner who is a Canadian citizen Vicrey auction is a bidding system where each bidder is required to put his or her bid in a sealed envelope to prevent other bidders from knowing what amount he or she is bidding.

The Collector should bid a price that he or she is willing to pay for the statue,this is ensure that he is will not feel cheated at the end of the entire process. IN THIS BIDDING SYSTEM THE PRICE PAID IS THE SECOND-PRICE BID PRICE AND NOT THE WINNING BID PRICE.

8 0
2 years ago
A spherical tank for storing gas under pressure is 25 m in diameter and is made of steel 15 mm thick. The yield point of the mat
nalin [4]

Answer:

a) (option B) 230 kPa

b) (option A) 100 N/m

Explanation:

Given:

Diameter, d = 25 m

Thicknesses, t = 15 mm

Yield point = 240 MPa

Factor of safety = 2.5

a) To find the maximum internal pressure, let's use the formula:

\sigma l = \frac{\sigma y}{FOS} = \frac{PD}{4t}

\frac{\sigma y}{FOS} = \frac{PD}{4t}

Solving for P, we have:

P = \frac{\sigma y * 4t}{FOS * D}

P = \frac{240 * 4 * 15}{2.5 * 25}

P = 230.4 kPa

≈ 230 kPa

The maximum permissible internal pressure is nearly 230kPa

b) Given:

Thickness, t = 6.35 mm

L = 203 mm

Torque, T = 8 N m

Let's find the mean Area,

mA = (l - t)²

= (203 - 6.5)²

= 38671.22mm²

≈ 0.03867 m² (converted to meters)

To find the average shear flow, let's use the formula:

q = \frac{T}{2* mA}

= \frac{8}{2 * 0.03867}

q = 103.4 N/m approximately 100N/m

The average shear force flow is most nearly 100 N/m

4 0
2 years ago
Read 2 more answers
Determine F12 and F21 for the following configurations: (a) A long semicircular duct with diameter of 0.1 meters: (b) A hemisphe
uysha [10]

Answer:

long duct: 1.0 and 0.424

Hemisphere 1.0 ; 0.125; 0.5

Explanation:

For a long duct:

By inspection, F_{12} = 1.0

Calculating by reciprocity, F_{21} = \frac{A_{1} }{A_{2}F_{12}  }  = \frac{2RL}{\frac{3}{4}*2\pi RL  }* 1.0\\                                                         = 0.424

Hemisphere:

By reciprocity gives = 0.125

using the summation rule: F_{21} + F_{22} + F_{23} = 1

However, because this is a hemisphere, the value will be= 0.5 * 1

                                                                                               = 0.5

6 0
2 years ago
Q10. Select the correct option for the following questions – (10 points, 2 each) a. After an edge dislocation has passed through
Gnom [1K]

Answer:

a. True - Because the atomic arrangements of that region is disorderer because of the extra half plane atoms in between the line

b.Slip

C. Strength theoretical is greater than strength experimental

d. Shear stress

e. Highest linear density

4 0
2 years ago
Chapter 19: Diesel Engine Operation and Diagnosis -Chapter Quiz
Llana [10]

Answer: See explanation

Explanation:

1. How is diesel fuel ignited in a warm diesel engine?

B. Heat compression

2. Which type of diesel injection produces less noise?

A. Indirect injection (IDI)

3. Which diesel injection system requires the use of a glow plug?

A. Indirect injection (IDI)

4. The three phases of diesel ignition include:

C. Ignition delay, repaid combustion, controlled combustion.

5. What fuel system component is used in a vehicle equipped with a diesel engine that is seldom used on the same vehicle when it is equipped with a gasoline engine?

D. Water-fuel separator

6. The diesel injection pump is usually driven by a _________________.

A. Gear off the camshaft

7. Which diesel system supplies high-pressure diesel fuel to all the injectors all of the time?

C. High-pressure common rail

8. Glow plugs should have high resistance when _____________and lower resistance when __________________.

B. Warm/cold

9. Technician A says that glow plugs are used to help start a diesel engine and are shut off as soon as the engine starts. Technician B says that the glow plugs are turned off as soon as a flame is detected in the combustion chamber. Which Technician is correct?

D. Neither Technicians A NOR B

10. What part should be removed to test cylinder compression on a diesel engine?

D. A glow plug

6 0
2 years ago
Other questions:
  • generally compound curves are not filtered recommended for A. Road B. water way C. underground road D. rail way​
    12·1 answer
  • As shown, a load of mass 10 kg is situated on a piston of diameter D1 = 140 mm. The piston rides on a reservoir of oil of depth
    9·1 answer
  • Some states have osha programs, but you should always defer to the federal program.
    8·2 answers
  • Your assignment is to write a menu driven program. The menu will be responded to using a switch statement. The menu options (cas
    6·1 answer
  • A fireboat is to fight fires at coastal areas by drawing seawater with a density of 1030 kg/m through a 20-cm-diameter pipe at a
    13·1 answer
  • An uninsulated, thin-walled pipe of 100-mm diameter is used to transport water to equipment that operates outdoors and uses the
    9·1 answer
  • A mixture of air and methane is formed in the inlet manifold of a natural gas-fueled internal combustion engine. The mole fracti
    14·1 answer
  • Water enters a circular tube whose walls are maintained at constant temperature at specified flow rate and temperature. For full
    8·1 answer
  • Technician A says that weld-through primer can be removed from the immediate weld area to improve weld quality. Technician B say
    7·1 answer
  • Why is data driven analytics of interest to companies?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!