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
Ronny wants to calculate the mechanical advantage. He needs to determine the length of the effort arm and the length of the load
kakasveta [241]

Answer:

I hope it's helpful.

Explanation:

Simple Machines

Experiments focus on addressing areas pertaining to the relationships between effort force, load force, work, and mechanical advantage, such as: how simple machines change the force needed to lift a load; mechanical advantages relation to effort and load forces; how the relationship between the fulcrum, effort and load affect the force needed to lift a load; how mechanical advantage relates to effort and load forces and the length of effort and load arms.

Through investigations and models created with pulleys and levers, students find that work in physical terms is a force applied over a distance. Students also discover that while a simple machine may make work seem easier, in reality the amount of work does not decrease. Instead, machines make work seem easier by changing the direction of a force or by providing mechanical advantage as a ratio of load force to effort force.

Students examine how pulleys can be used alone or in combination affect the amount of force needed to lift a load in a bucket. Students find that a single pulley does not improve mechanical advantage, yet makes the effort applied to the load seem less because the pulley allows the effort to be applied in the direction of the force of gravity rather than against it. Students also discover that using two pulleys provides a mechanical advantage of 2, but that the effort must be applied over twice the distance in order to gain this mechanical advantage Thus the amount of work done on the load force remains the same.

Students conduct a series of experiments comparing the effects of changing load and effort force distances for the three classes of levers. Students discover that when the fulcrum is between the load and the effort (first class lever), moving the fulcrum closer to the load increases the length of the effort arm and decreases the length of the load arm. This change in fulcrum position results in an increase in mechanical advantage by decreasing the amount of effort force needed to lift the load. Thus, students will discover that mechanical advantage in levers can be determined either as the ratio of load force to effort force, or as the ratio of effort arm length to load arm length. Students then predict and test the effect of moving the fulcrum closer to the effort force. Students find that as the length of the effort arm decreases the amount of effort force required to lift the load increases.

Students explore how the position of the fulcrum and the length of the effort and load arms in a second-class lever affect mechanical advantage. A second-class lever is one in which the load is located between the fulcrum and the effort. In a second-class lever, moving the load changes the length of the load arm but has no effect on the length of the effort arm. As the effort arm is always longer than the load arm in this type of lever, mechanical advantage decreases as the length of the load arm approaches the length of the effort arm, yet will always be greater than 1 because the load must be located between the fulcrum and the effort.

Students then discover that the reverse is true when they create a third-class lever by placing the effort between the load and the fulcrum. Students discover that in the case of a third-class lever the effort arm is always shorter than the load arm, and thus the mechanical advantage will always be less than 1. Students also create a model of a third-class lever that is part of their daily life by modeling a human arm.

The CELL culminates with a performance assessment that asks students to apply their knowledge of simple machine design and mechanical advantage to create two machines, each with a mechanical advantage greater than 1.3. In doing so, students will demonstrate their understanding of the relationships between effort force, load force, pulleys, levers, mechanical advantage and work. The performance assessment will also provide students with an opportunity to hone their problem-solving skills as they test their knowledge.

Through this series of investigations students will come to understand that simple machines make work seem easier by changing the direction of an applied force as well as altering the mechanical advantage by afforded by using the machine.

Investigation focus:

Discover that simple machines make work seem easier by changing the force needed to lift a load.

Learn how effort and load forces affect the mechanical advantage of pulleys and levers.

8 0
2 years ago
What are the atomic binding force and energy? how do they relate to materials strength and thermal stability.
Elanso [62]

Answer:

As we know that every molecule is attached by a strong force .The force required to disassemble the atoms is know as atomic binding force or we can say that the force required to disassemble the electron from atoms is known as binding force.On the other hand the energy require to doing this is known as atomic binding energy.

If the binding force is high then it will become difficult to disassemble thermally as well as mechanically.So we can say that it have direct relationship with   materials strength and thermal stability.

7 0
3 years ago
Select the correct answer.
cricket20 [7]

Answer:

A.

The power generated by a wind farm is not constant because of irregular wind patterns.

5 0
3 years ago
A formal indication from a state, on letterhead, or an official state form, that shows the applicant has valid driving privilege
alex41 [277]

A formal indication from a state, on letterhead, or an official state form, which shows that an applicant has valid driving privileges and is clear to apply for a Colorado driver's license is called a clearance.

<h3>What is a learner's license?</h3>

A learner's license is also referred to as learner's permit and it can be defined as a category of driver's license that is issued to an individual who is learning how to drive an automobile vehicle (car).

<h3>What is a license?</h3>

A license is also referred to as a certificate and it can be defined as an authorization that is typically issued by state governments to a driver, so as to avail him or her the legal ability to physically driver in all the states across a country.

In this scenario, we can infer and logically deduce that a clearance is a formal indication from a state which shows and affirms that an applicant has valid driving privileges, and is permitted to apply for a Colorado driver's license.

Learn more about learner's license here: brainly.com/question/26289148

#SPJ1

7 0
1 year ago
Describe each occupation
vitfil [10]

Answer:

Carpenter — A carpenter is someone who works with wood. They build houses and make cabinets etc.

Logging —  Loggers are people who cut trees. They use strong chain saws to cut trees.

Shipwrights — Shipwrights build, design, and repair all sizes of boats.

Wood Machinist — Wood Machinists repair and cut timber or any kind of wood for construction projects. They also operate woodworking machines, as their name suggest.

Furniture finishers —  Furniture finishers shape, decorate, and restore damaged and worn out furniture.

5 0
3 years ago
Other questions:
  • If a torque of M = 300 N⋅m is applied to the flywheel, determine the force that must be developed in the hydraulic cylinder CD t
    13·1 answer
  • If there are 16 signal combinations (states) and a baud rate (number of signals/second) of 8000/second, how many bps could I sen
    7·1 answer
  • Anyone have any good ways of revisiting <br> Or <br> Have any good study notes
    11·1 answer
  • A milling operation was used to remove a portion of a solid bar of square cross section. Forces of magnitude P = 18 kN are appli
    15·1 answer
  • Hi, I have an assignment in which i needs to write a report on (Rationalization of electrical energy consumption) and i need cha
    6·1 answer
  • In order to avoid slipping in the shop, your footwear should __
    10·2 answers
  • Consider an InSb NW with ballistic mean free path of 150nm. Calculate the current through a 250nm long InSb NW when a 100mV bias
    6·1 answer
  • A 200 W vacuum cleaner is powered by an electric motor whose efficiency is 70%. (Note that the electric motor delivers 200 W of
    13·1 answer
  • I wuv little space :)
    8·1 answer
  • How do guest room hotel smoke alarms work and differ then regular home versions?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!