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
EastWind
28 days 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:
iogann1982 [279]28 days ago
5 0

Answer:

Explanation:

Un dato importante: la división entera elimina la parte fraccionaria. Por lo tanto, el promedio de 8, 10, 5 y 4 se presenta como 6, no 6.75.

Observación: Las pruebas incluyen cuatro valores de entrada muy grandes cuyo producto causa desbordamiento. No necesitas hacer nada especial, solo ten en cuenta que la salida no representa el producto correcto (en realidad, el resultado de cuatro números positivos es negativo; sorprendente).

Envía lo anterior para evaluación. Tu programa no pasará las últimas pruebas (eso es normal) hasta que completes la segunda parte a continuación.

Parte 2: Además, se debe calcular e imprimir el producto y promedio usando aritmética de punto flotante.

Presenta cada número de punto flotante con tres dígitos después del punto decimal, lo cual puedes hacer así: System.out.printf("%.3f", tuValor);

Ejemplo: Si la entrada es 8, 10, 5, 4, la salida sería:

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

choli [191]28 days ago
4 0

Answer:

Abajo se presenta el código completo con explicaciones detalladas y los resultados de salida.

Código con Explicación Parte-1:

#include <stdio.h>

int main()

{

// Se define un arreglo de cuatro enteros de tipo int para almacenar los datos ingresados por el usuario

int number[4];

// Variables de tipo int para almacenar el resultado del producto y promedio de los números

int prod, avg;

printf("Por favor, ingresa cuatro enteros: ");

// Se obtienen cuatro enteros del usuario; el especificador %d se usa para int

scanf("%d %d %d %d",&number[0],&number[1],&number[2],&number[3]);

// Se calcula el producto de los números multiplicándolos entre sí

prod = number[0] * number[1] * number[2] * number[3];

// Se calcula el promedio dividiendo la suma de los números por el total de números

avg = (number[0] + number[1] + number[2] + number[3]) / 4;

// Se imprime el producto y el promedio de los números

printf("El producto de los cuatro números es = %d\n", prod);

printf("El promedio de los cuatro números es = %d", avg);

return 0;

}

Salida Parte-1:

Por favor, ingresa cuatro enteros: 8 10 5 4

El producto de los cuatro números es = 1600

El promedio de los cuatro números es = 6

Como puedes observar, al usar el tipo int no estamos obteniendo el valor exacto del promedio.

Código con Explicación Parte-2:

#include <stdio.h>

int main()

{

// Aquí simplemente cambiamos el tipo de int a float

float number[4];

float prod, avg;

printf("Por favor, ingresa cuatro enteros: ");

// %f se utiliza para números de punto flotante

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 se usa para mostrar hasta 3 dígitos decimales

printf("El producto de los cuatro números es = %0.3f\n", prod);

printf("El promedio de los cuatro números es = %0.3f", avg);

return 0;

}

Salida Parte-2:

Por favor, ingresa cuatro enteros: 8 10 5 4

El producto de los cuatro números es = 1600.000

El promedio de los cuatro números es = 6.750

Como puedes notar, al utilizar el tipo float ahora obtenemos el valor exacto del promedio.

You might be interested in
Let Deterministic Quicksort be the non-randomized Quicksort which takes the first element as a pivot, using the partition routin
Daniel [215]
For Deterministic Quicksort, which operates by selecting the first element as the pivot, consider a scenario where the pivot consistently divides the array into segments of 1/3 and 2/3 for all recursive calls. (a) The runtime recurrence for this case needs to be determined. (b) Use a recursion tree to justify that this recurrence resolves to Theta(n log n). (c) Provide distinct sequences of 4 and 13 numbers that prompt this behavior.
3 0
7 days ago
The force of magnitude F acts along the edge of the triangular plate. Determine the moment of F about point O. Find the general
Daniel [215]

Answer:

  M_o = 18.84 N*m clockwise.  

Explanation:

Given:

- Force F = 120 N

- Length b = 610 mm

- Height h = 330 mm

Required:

Calculate the moment M_o at the origin and its direction:

Solution:

- The force is divided into components F_x and F_y along the base b and height h, respectively:

                    F_x = F*cos(Q)

                    F_x = F*(h / sqrt(h² + b²))

                    F_x = 120*(330 / sqrt(330² + 610²))

                    F_x = 57.098 N

- The F_y component can be excluded as it passes through the origin, resulting in zero moment.

- The moment at point O is calculated as:

                     M_o = F_x * h

                     M_o = 57.098*.33

                    M_o = 18.84 N*m clockwise.  

3 0
9 days ago
A long, horizontal, pressurized hot water pipe of 15cm diameter passes through a room where the air temperature is 24degree C. T
Daniel [215]
The heat transfer rate to the surrounding air per meter of pipe length is quantified as 521.99 W/m. Given the negligible radiation losses from the pipe, convection remains the sole method of heat transfer. The rate of heat transfer via convection can be defined as such, using the specified heat transfer coefficient of 10.45 for air and calculating the surface area of the pipe.
5 0
7 days ago
Dalton needs to prepare a close-out report for his project. Which part of the close-out report would describe
alex41 [274]

Response:

Dalton

The segment of the close-out document that outlines future project planning and management strategies is:

overview of project management success

Details:

The Project Close-out Report is a crucial project management document that highlights any deviations from initial plans. These discrepancies are described in terms of project performance, cost, and timeline. The report signifies the conclusion of the project and the transfer of deliverables to the relevant parties. It includes a summary of project management success, detailing the goals set for the project, accomplishments, and insights gained from the experience.

4 0
1 month ago
Kim wants a candy bar and tries to convince her father to purchase one for her by threatening to throw a fit in the crowded groc
alex41 [274]

pressure tactic Response:

Reasoning:

because the child will shame the parents, leading them to give in to the child's demands.

5 0
1 day ago
Other questions:
  • A manometer measures a pressure difference as 40 inches of water. Take the density of water to be 62.4 lbm/ft3.What is this pres
    13·1 answer
  • Which of the following ranges depicts the 2% tolerance range to the full 9 digits provided?
    6·1 answer
  • A pitfall cited in Section 1.10 is expecting to improve the overall performance of a computer by improving only one aspect of th
    6·1 answer
  • 6. You are evaluating flow through an airway. The current flow rate is 10 liters per minute with a fixed driving pressure (P1) o
    5·1 answer
  • At a certain elevation, the pilot of a balloon has a mass of 120 lb and a weight of 119 lbf. What is the local acceleration of g
    6·1 answer
  • Consider a very long, slender rod. One end of the rod is attached to a base surface maintained at Tb, while the surface of the r
    8·1 answer
  • A pipe in a district heating network is transporting over-pressurized hot water (10 atm) at a mass flow of 0.5 kg/s. The pipe is
    14·1 answer
  • Consider film condensation on a vertical plate. Will the heat flux be higher at the top or at the bottom of the plate? Why?
    5·1 answer
  • A cylinder with a 6.0 in. diameter and 12.0 in. length is put under a compres-sive load of 150 kips. The modulus of elasticity f
    5·1 answer
  • 4.68 Steam enters a turbine in a vapor power plant operating at steady state at 560°C, 80 bar, and exits as a saturated vapor at
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!