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]
4 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]4 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]4 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
Why is the contractor normally required to submit a bid bond when making a proposal to an owner on a competitively bid contract?
just olya [345]

Answer:

It serves as a guarantee that the contractor who wins the bid will honor the terms of the bid after the contract is signed.

Explanation:

A bid bond is a type of construction bond that protects the obligee in a  construction bidding process.

A bid bond typically involves three parties:

The obligee; the owner or developer of the construction project under bid. The principal; the bidder or proposed contractor.

The surety; the agency that issues the bid bond to the principal example insurance company or bank.

A bid bond generally serves as a guarantee that the contractor who wins the bid will honor the terms of the bid after the contract is signed.

3 0
3 years ago
A defective crankshaft position sensor is a common cause of a no-start condition.
ohaa [14]

Answer:

Switching on and off

Explanation:

No starters are often caused by a faulty crankshaft actuator. The signals from this transmitter is sent to the ignition module, which turns in and out of the ignition system. If you already have an RPM sign, it's possible that a faulty ignition unit or PCM isn't turning the coils on and off. Along with button on and the motor cranking, testing for volts at the contacts with a voltmeter.

3 0
3 years ago
Design a filter that has infinite DC gain, a gain of one from 1Hz to 100 Hz and filters (1storder) any signals above 100 Hz.a) S
EastWind [94]

Answer:

Attached below are the  sketches

answer :

c) G(s) = 100 / ( s + 100 )

d) y'(t)  + 100Y(s) = 100 X(s)

e) g(t) = e^-100t  u(t)

Explanation:

a) Sketch the bode plot

The filter here is a low pass filter

b) Sketch the s-plane

attached below.     pole ( s ) is at 100

c) write the transfer function of the filter

Transfer function ; G(s) = 100 / ( s + 100 )

d) write the differential equation

Y(s) / X(s) = 100 / s + 100

Y(s) [ s + 100 ] = 100 X(s)

= sY(s) + 100Y = 100 X(s)

∴ differential equation = y'(t)  + 100Y(s) = 100 X(s)

e) write out the unforced transient response

g(t) = e^-100t  u(t)

f) write out the frequency response

attached below

4 0
3 years ago
Diodes can be used to protect electronic components from certain flowing in another Direction describe another application outsi
Anvisha [2.4K]

Answer:

Plumbing  using a one-way check valve to stop water flowing back on a pump when the pump shuts off.

Explanation:

Diodes are like check valves, keeping current from flowing both ways.  Used to create d.c. out of a.c by rectification.  Also to block flow if d.c. power like a battery is hooked up in reverse polarity.

4 0
3 years ago
What is the real name of the town that Bud &amp; Bugs stayed in while they were waiting for the train?
Leona [35]

Answer: Hooverville

Explanation:

Bud, not Buddy is a book about a ten years old boy who ran away from home where he stayed with his foster parents. He was treated unfairly and beaten.

He left home to seek a better living and hope that he will find his father as well. He met another orphan named Bugs and they decided to go to Hooverville so that they can get a train going to California.

6 0
3 years ago
Other questions:
  • David wants to determine what his organization should do in the future, and set project targets. Which management function can D
    14·1 answer
  • What is the lehr and what purpose does it serve?
    5·1 answer
  • What is the entropy of a closed system in which 25 distinguishable grains of sand are distributed among 1000 distinguishable equ
    5·2 answers
  • You are given the following information about a drybatch paving operation. You are going to use one mixer that has a service rat
    10·1 answer
  • N2 flows through an insulated horizontal tube at steady state. With an inlet temperature of 150°C and a velocity change from 2 m
    11·1 answer
  • The sports car has a weight of 4900 lblb and center of gravity at GG. If it starts from rest it causes the rear wheels to slip a
    13·1 answer
  • Legal metrology would protect consumers from businesses that do not take measurements according to defined measuring regulations
    7·1 answer
  • SM Success Maker
    11·1 answer
  • Which of the following is a measurement at the nominal level?
    8·1 answer
  • 4. When the ESC system senses oversteer,
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!