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
What is a radio wave made up of? Molecules? Electrons? Other?
mafiozo [28]

Radio waves are radiated by charged particles when they are accelerated. They are produced artificially by time-varying electric currents, consisting of electrons flowing back and forth in a specially-shaped metal conductor called an antenna. ... Radio waves are received by another antenna attached to a radio receiver.

4 0
3 years ago
Read 2 more answers
A vertical pole consisting of a circular tube of outer diameter 127 mm and inner diameter 115 mm is loaded by a linearly varying
Anna [14]

Maximum shear stress in the pole is 0.

<u>Explanation:</u>

Given-

Outer diameter = 127 mm

Outer radius,r_{2} = 127/2 = 63.5 mm

Inner diameter = 115 mm

Inner radius, r_{1} = 115/2 = 57.5 mm

Force, q = 0

Maximum shear stress, τmax = ?

 τmax  = \frac{4q}{3\pi } (\frac{r2^2 + r2r1 + r1^2}{r2^4 - r1^4} )

If force, q is 0 then τmax is also equal to 0.

Therefore, maximum shear stress in the pole is 0.

3 0
3 years ago
What are the benefits of using the engineering design process? combining scientific knowledge and creativity in a rigid and stru
Trava [24]

Answer:

combining scientific knowledge, careful reasoning, and artistic invention in a flexible approach to problem-solving

Explanation:

7 0
3 years ago
Steam enters a turbine steadily at 7 MPa and 600°C with a velocity of 60 m/s and leaves at 25 kPa with a quality of 95 percent.
Rufina [12.5K]

Answer:

a) \dot m = 16.168\,\frac{kg}{s}, b) v_{out} = 680.590\,\frac{m}{s}, c) \dot W_{out} = 18276.307\,kW

Explanation:

A turbine is a steady-state devices which transforms fluid energy into mechanical energy and is modelled after the Principle of Mass Conservation and First Law of Thermodynamics, whose expressions are described hereafter:

Mass Balance

\frac{v_{in}\cdot A_{in}}{\nu_{in}} - \frac{v_{out}\cdot A_{out}}{\nu_{out}} = 0

Energy Balance

-q_{loss} - w_{out} + h_{in} - h_{out} = 0

Specific volumes and enthalpies are obtained from property tables for steam:

Inlet (Superheated Steam)

\nu_{in} = 0.055665\,\frac{m^{3}}{kg}

h_{in} = 3650.6\,\frac{kJ}{kg}

Outlet (Liquid-Vapor Mix)

\nu_{out} = 5.89328\,\frac{m^{3}}{kg}

h_{out} = 2500.2\,\frac{kJ}{kg}

a) The mass flow rate of the steam is:

\dot m = \frac{v_{in}\cdot A_{in}}{\nu_{in}}

\dot m = \frac{\left(60\,\frac{m}{s} \right)\cdot (0.015\,m^{2})}{0.055665\,\frac{m^{3}}{kg} }

\dot m = 16.168\,\frac{kg}{s}

b) The exit velocity of steam is:

\dot m = \frac{v_{out}\cdot A_{out}}{\nu_{out}}

v_{out} = \frac{\dot m \cdot \nu_{out}}{A_{out}}

v_{out} = \frac{\left(16.168\,\frac{kg}{s} \right)\cdot \left(5.89328\,\frac{m^{3}}{kg} \right)}{0.14\,m^{2}}

v_{out} = 680.590\,\frac{m}{s}

c) The power output of the steam turbine is:

\dot W_{out} = \dot m \cdot (-q_{loss} + h_{in}-h_{out})

\dot W_{out} = \left(16.168\,\frac{kg}{s} \right)\cdot \left(-20\,\frac{kJ}{kg} + 3650.6\,\frac{kJ}{kg} - 2500.2\,\frac{kJ}{kg}\right)

\dot W_{out} = 18276.307\,kW

6 0
3 years ago
Q5
Klio2033 [76]

The C++ code that would draw all the iterations in the selection sort process on the array is given below:

<h3>C++ Code</h3>

#include <stdio.h>

#include <stdlib.h>

int main() {

   int i, temp1, temp2;

   int string2[16] = { 0, 4, 2, 5, 1, 5, 6, 2, 6, 89, 21, 32, 31, 5, 32, 12 };

   _Bool check = 1;

   while (check) {

       temp1 = string2[i];

       temp2 = string2[i + 1];

       if (temp1 < temp2) {

           string2[i + 1] = temp1;

           string2[i] = temp2;

           i = 0;

       } else {

           i++;

           if (i = 15) {

               check = !check;

           }

       }

   }

   

   return 0;

}

Read more about C++ programming here:

brainly.com/question/20339175

#SPJ1

5 0
1 year ago
Other questions:
  • What's mutual inductance​
    8·1 answer
  • Calculate the load, PP, that would cause AA to be displaced 0.01 inches to the right. The wires ABAB and ACAC are A36 steel and
    10·1 answer
  • True/False<br> An anemometer displays wind direction, wind speed, altitude and type of precipitation
    12·1 answer
  • Briefly explain why small-angle grain boundaries are not as effective in interfering with the slip process as are high-angle gra
    5·1 answer
  • write an interface downloadable that has a method "geturl" that returns the url of a downloadable object
    5·1 answer
  • Liquid water is fed to a boiler at 24°C and 10 bar is converted at a constant pressure to saturated steam.
    12·1 answer
  • In an experiment, the local heat transfer over a flat plate were correlated in the form of local Nusselt number as expressed by
    5·1 answer
  • What drives up the cost of consumables?
    6·1 answer
  • What is the function rule for the line? f(x)=−32x−2f(x)=−23x−2f(x)=32x−2f(x)=−32x+2A coordinate grid with x and y axis ranging f
    6·1 answer
  • How much energy in joule is added to a 12 g of sample of aluminum (c=0.897 J/g ◦C) to raise the temperature from 20 ◦C to 45 ◦C?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!