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
Calculate and plot the radial and circumferential stress distribution in the left ventricle at the end of systole (p 5 80 mmHg;
alexandr402 [8]

Answer:

62990.08 N/M

Explanation:

Circumferential stress, or hoop stress, a normal stress in the tangential (azimuth) direction. axial stress, a normal stress parallel to the axis of cylindrical symmetry. radial stress, a stress in directions coplanar with but perpendicular to the symmetry axis.

See attachment for the step by step solution of the given problem..

8 0
2 years ago
Four of the minterms of the completely specified function f(a, b, c, d) are m0, m1, m4, and m5.
Sveta_85 [38]

Complete Question

The complete question is shown on the first uploaded image

Answer:

a) The required additional minterms  for f so that f has eight primary implicants with two literals and no other prime implicant are m_{2},m_{3},m_{7},m_{8},m_{11},m_{12},m_{13},m_{14} and m_{15}

b) The essential prime implicant are c' d',a'b',ab and cd

c) The minimum sum-of-product expression for f are

                  a'b' +ab +c'd'+cd+a'c',\\ a'b'+ab+c'd'+cd+a'd,\\a'b'+ab+c'd'+cd+bc'  and  \\ a'b'+ab+c'd' +cd+bd

Explanation:

The explanation is shown on the second third and fourth image

8 0
2 years ago
What should you release to re-establish vehicle control and tire traction?
MrMuchimi

Answer: The accelerator and the brakes.

6 0
2 years ago
QUESTION 3
lianna [129]
D D D D D D D D D D D D D D D DdDdddddf
6 0
3 years ago
A resistivity meter is measured in
Bingel [31]
Ohms ..................
3 0
2 years ago
Read 2 more answers
Other questions:
  • Consider the following pulley system. A block of mass m is connected to a translational spring of stiffness k through a cable, w
    10·1 answer
  • The density of oxygen contained in a tank is 2.0 kg/m3 when the temperature is 25 °C. Determine the gage pressure of the gas if
    12·1 answer
  • What are supercapacitors ?
    13·2 answers
  • The entire population of a given community is examined, and all who are judged to be free from bowel cancer are questioned exten
    12·1 answer
  • What considerations are included in the Preliminary Floodproofing/Retrofitting Preference Matrix?
    7·1 answer
  • A non-entrepreneurship, work-based, agricultural type of SAE, in which a student learns and gains skills in a paid or unpaid pos
    15·1 answer
  • Why is data driven analytics of interest to companies?
    9·1 answer
  • Think about the KIA factory shown in the video, what are two things that managers could do to reduce waste or increase efficienc
    6·1 answer
  • Hey answer quick for 20 points
    7·2 answers
  • What is the creative process that helps you overcome writer's block called?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!