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
Is there a way to get the answers to a NCCER book test?
sergeinik [125]

Answer:

go on google and type NCEER book answers

3 0
3 years ago
The Hoover Dam is 221 m tall and 379 m wide. Approximating it as a flat plate, determine the effective resultant force on the da
IrinaVladis [17]

Answer:

2165800 Pa

Explanation:

See it in the pic.

3 0
3 years ago
A standard penetration test has been conducted on a coarse sand at a depth of 16 ft below the ground surface. The blow counts ob
scoray [572]

Solution :

Given :

The number of blows is given as :

0 - 6 inch = 4 blows

6 - 12 inch = 6 blows

12 - 18 inch = 6 blows

The vertical effective stress $=1500 \ lb/ft^2$

                                              $= 71.82 \ kN/m^2$

                                             $ \sim 72 \ kN/m^2 $

Now,

$N_1=N_0 \left(\frac{350}{\bar{\sigma}+70} \right)$

$N_1 = $ corrected N - value of overburden

$\bar{\sigma}=$ effective stress at level of test

0 - 6 inch, $N_1=4 \left(\frac{350}{72+70} \right)$

                      = 9.86

6 - 12 inch, $N_1=6 \left(\frac{350}{72+70} \right) $

                        = 14.8

12 - 18 inch, $N_1=6 \left(\frac{350}{72+70} \right) $

                         = 14.8

$N_{avg}=\frac{9.86+14.8+14.8}{3}$

       = 13.14

       = 13

8 0
3 years ago
I. Draw the velocity diagram for the instant shown and determine the velocity of
trapecia [35]

Answer:

?????????????????????????????????????

3 0
3 years ago
1.Which thematic group uses technology to direct the behavior of dynamical systems, ensuring that they behave in a predictable m
dsp73

The thematic group governing the behavior of dynamic system is control system, and the one packaging the miniature components to conduct electricity is electronic system. Thus, option E is correct.

<h3>What are thematic groups?</h3>

The thematic groups comprises of group of people that work over the same idea or the concept. The thematic groups working on different projects and ideas comprised to work with different systems.

The control of dynamic system in order to produce the desirable outcome has been the role of the control system.

The packaging of the electronic miniatures in system that performs the role of direction of electricity is the role of electronic system thematic group. Thus, option E is correct.

Learn more about thematic group, here:

brainly.com/question/32731

#SPJ1

8 0
2 years ago
Other questions:
  • A mysterious device found in a forgotten laboratory accumulates charge at a rate specified by the expression gm = 9 - 10tC from
    13·1 answer
  • A fluid flows steadily through a pipe with a uniform cross sectional area. The density of the fluid decreases to half its initia
    6·1 answer
  • Calculate the value of ni for gallium arsenide (GaAs) at T = 300 K. The constant B = 3. 56 times 1014 9cm -3 K-3/2) and the band
    9·1 answer
  • Technician A says that most states will allow landfills to dispose of whole tires with a permit. Technician B says that landfill
    5·1 answer
  • Alberta Einstein teaches a business class at Podunk University. To evaluate the students in this class, she has given three test
    13·1 answer
  • Energy that causes a transfer of heat between marterials
    13·1 answer
  • Using the idea of mass and change of speed... could a bowling ball be thrown so fast that it has the same force as a car driving
    7·1 answer
  • The water of a 14’ × 48’ metal frame pool can drain from the pool through an opening at the side of the pool. The opening is abo
    13·1 answer
  • Two aerial photographs were taken 30 seconds apart over one east-bound lane of l-80 near Grand Island, NE. The following results
    12·1 answer
  • What parts do all circuits have in common?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!