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
You want to determine whether the race of the defendant has an impact on jury verdicts. You assign participants to watch a trial
Andru [333]

Answer:

The confidence scale represents an ordinal scale of measurement

Explanation:

An ordinal scale or level of measurement is used to measure attributes that can be ranked or ordered, but the interval between the attributes do not have quantitative significance. In this case, the measurement was done on a scale of 1 - 7, with a "1" being; not all that race of defendant has an impact on jury verdicts and a "7" being "very" meaning that race indeed has impact on jury verdicts. Another example can be a survey carried out on the level of customer satisfaction on a particular product, with "1" most dissatisfied and "10 " representing most satisfied. In the first example, it is wrong to say that the difference between 1 being "not at all" and maybe 3 is the same as the difference between 5 and 7 which have different connotations, because the numbers are merely for tagging and not to quantify.

Other levels of measurement include:

1. Nominal: this is the simplest level of measurement and it is simply used to categorize the attributes. Example is taking a survey on gender in the categories of male, female and transgender.

2. Interval: the interval scale is used when the distance between two attributes have meanings but there is no true zero value associated with the scale.

3. Ratio: this combines all the other three levels of measurement and is used to categorize, used to show ranking, has meaningful distances between the attributes and the scale has a true zero point. Example is the measurement of temperature using the celcius scale thermometer, where there is a true zero point at 0°C and the distance between 5°C and 10°C is the same as the distance between 10°C and 15°C.

6 0
3 years ago
Fix the code so the program will run correctly for MAXCHEESE values of 0 to 20 (inclusive). Note that the value of MAXCHEESE is
GarryVolchara [31]

Answer:

Code fixed below using Java

Explanation:

<u>Error.java </u>

import java.util.Random;

public class Error {

   public static void main(String[] args) {

       final int MAXCHEESE = 10;

       String[] names = new String[MAXCHEESE];

       double[] prices = new double[MAXCHEESE];

       double[] amounts = new double[MAXCHEESE];

       // Three Special Cheeses

       names[0] = "Humboldt Fog";

       prices[0] = 25.00;

       names[1] = "Red Hawk";

       prices[1] = 40.50;

       names[2] = "Teleme";

       prices[2] = 17.25;

       System.out.println("We sell " + MAXCHEESE + " kind of Cheese:");

       System.out.println(names[0] + ": $" + prices[0] + " per pound");

       System.out.println(names[1] + ": $" + prices[1] + " per pound");

       System.out.println(names[2] + ": $" + prices[2] + " per pound");

       Random ranGen = new Random(100);

       // error at initialising i

       // i should be from 0 to MAXCHEESE value

       for (int i = 0; i < MAXCHEESE; i++) {

           names[i] = "Cheese Type " + (char) ('A' + i);

           prices[i] = ranGen.nextInt(1000) / 100.0;

           amounts[i] = 0;

           System.out.println(names[i] + ": $" + prices[i] + " per pound");

       }        

   }

}

7 0
3 years ago
Air at 40C flows over a 2 m long flat plate with a free stream velocity of 7 m/s. Assume the width of the plate (into the paper)
mezya [45]

Complete Question

Air at 40C flows over a 2 m long flat plate with a free stream velocity of 7m/s. Assume the width of the plate (into the paper) is 0.5 m. If the plate is at a co temperature of 100C,find:

The total heat transfer rate from the plate to the air

Answer:

q=1.7845

Explanation:

From the question we are told that:

Air Temperature T_1=40c

Length l=2m

Velocity v=7m/s

Width w=0.5

Constant temperature T_t= 100C

Generally the equation for Total heat Transfer is mathematically given by

 q=hA(T_s-T_\infty)

Where

h=Convective heat transfer coefficient

 h=29.9075w/m^2k

Therefore

 q=h(L*B)(T_s-T_\infty)

 q=29.9075*(2*0.5)(100+273-(40+273))

 q=1794.45w

 q=1.7845

5 0
3 years ago
During the pre-drive check, you'll want to observe the car from the _______.
DENIUS [597]

Answer:

Passenger seat

Explanation:

If im wrong correct me

5 0
3 years ago
Design a program that calculates the area and circumstance of rectangle?​
Phantasy [73]
Let “w” and “L” be the width and length of the rectangle. “p” and “a” are perimeter and area
For python,
w=int(input(“width”))
l=int(input(“length”))
a= w*l
p=2*w+2*l
print(str(a), str(p)
4 0
2 years ago
Other questions:
  • A rubber wheel on a steel rim spins freely on a horizontal axle that is suspended by a fixed pivot at point P. When the wheel sp
    11·1 answer
  • CNG is a readily available alternative to
    5·1 answer
  • You are given a partial implementation of one header file, GildedRose.hpp. Item is a class that holds the information for each i
    6·1 answer
  • Question 11 (1 point)
    12·1 answer
  • How do you connect several springs to increase the equivalent stiffness? What is one example from industry or other real-life si
    7·1 answer
  • Find all the words, Figure out my puzzle!
    14·2 answers
  • Help me, iv been having problems with ads going in my phones storage files, what can i do to stop this?
    14·2 answers
  • Pleaseeee help me with this!!
    10·1 answer
  • Is A fine by the EPA may be imposed on the employer or
    8·1 answer
  • 9
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!