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
Note that common skills are listed toward the top, and less common skills are listed toward the bottom.
Sladkaya [172]

Answer:

BDEG

Explanation:

got it right on the test on edge because i used my b r a i n

5 0
3 years ago
CS3733: Homework/Practice 05 Suppose we would like to write a program called monitor which allows two other programs to communic
valina [46]

Answer:

#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<sys/types.h>

#include<string.h>

#include<pthread.h>

//#include<sys/wait.h>

int main(int argc, char** argv)

{

int fd1[2];

int fd2[2];

int fd3[2];

int fd4[2];

char message[] = "abcd";

char input_str[100];

pid_t p,q;

if (pipe(fd1)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd2)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd3)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd4)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

p = fork();

if (p < 0)

{

 fprintf(stderr, "fork Failed" );

return 1;

}

// child process-1

else if (p == 0)

{

 close(fd1[0]);// Close reading end of first pipe

 char concat_str[100];

 printf("\n\tEnter meaaage:"):

 scanf("%s",concat_str);

 write(fd1[1], concat_str, strlen(concat_str)+1);

 // Concatenate a fixed string with it

 int k = strlen(concat_str);

 int i;

 for (i=0; i<strlen(fixed_str); i++)

 {

  concat_str[k++] = fixed_str[i];

 }

 concat_str[k] = '\0';//string ends with '\0'

 // Close both writting ends

 close(fd1[1]);

 wait(NULL);

//.......................................................................

 close(fd2[1]);

 read(fd2[0], concat_str, 100);

 if(strcmp(concat_str,"invalid")==0)

 {

 printf("\n\tmessage not send");

 }

 else

 {

  printf("\n\tmessage send to prog_2(child_2).");

 }

 close(fd2[0]);//close reading end of pipe 2

 exit(0);

}

else

{

 close(fd1[1]);//Close writting end of first pipe

 char concat_str[100];

 read(fd1[0], concal_str, strlen(concat_str)+1);

 close(fd1[0]);

 close(fd2[0]);//Close writing end of second pipe

 if(/*check if msg is valid or not*/)

 {

  //if not then

  write(fd2[1], "invalid",sizeof(concat_str));

  return 0;

 }

 else

 {

  //if yes then

  write(fd2[1], "valid",sizeof(concat_str));

  close(fd2[1]);

  q=fork();//create chile process 2

  if(q>0)

  {

   close(fd3[0]);/*close read head offd3[] */

   write(fd3[1],concat_str,sizeof(concat_str);//write message by monitor(main process) using fd3[1]

   close(fd3[1]);

   wait(NULL);//wait till child_process_2 send ACK

   //...........................................................

   close(fd4[1]);

   read(fd4[0],concat_str,100);

   close(fd4[0]);

   if(sctcmp(concat_str,"ack")==0)

   {

    printf("Messageof child process_1 is received by child process_2");

   }

   else

   {

    printf("Messageof child process_1 is not received by child process_2");

   }

  }

  else

  {

   if(p<0)

   {

    printf("Chiile_Procrss_2 not cheated");

   }

   else

   {

     

    close(fd3[1]);//Close writing end of first pipe

    char concat_str[100];

    read(fd3[0], concal_str, strlen(concat_str)+1);

    close(fd3[0]);

    close(fd4[0]);//Close writing end of second pipe

    write(fd4[1], "ack",sizeof(concat_str));

     

   }

  }

 }

 close(fd2[1]);

}

}

8 0
3 years ago
Casein, a dairy product used in making cheese, contains 25% moisture when wet. A dairy sells this product for $40/100 kg. If req
Nataly_w [17]

Based on the percent moisture content of the dried product, the mass of dried casein produced os 852.3 kg.

<h3>What is the mass of casein in wet casein?</h3>

The mass of casein in 1000 Kg of wet casein is 75% 1000 kg = 750 Kg

Mass of water 250 kg

The mass of casein is constant while the moisture content can be changed.

At 12% moisture content;

750 kg = 88%%

100 % = 100 ×750/88 = 852.27 kg

Therefore, the mass of dried casein produced os 852.3 kg.

Learn more about mass at: brainly.com/question/24658038

#SPJ1

3 0
2 years ago
A 3 m aluminum pole is kept at a residential site for construction
Aliun [14]

Answer:

I don't know sorry

Explanation:

5 0
3 years ago
If we have silicon at 300K with 10 microns of p-type doping of 4.48*10^18/cc and 10 microns of n-type doping at 1000 times less
liq [111]

Answer:

The resistance is 24.9 Ω

Explanation:

The resistivity is equal to:

R=\frac{1}{N_{o}*u*V } =\frac{1}{4.48x10^{15}*1500*106x10^{-19}  } =0.93ohm*cm

The area is:

A = 60 * 60 = 3600 um² = 0.36x10⁻⁴cm²

w=\sqrt{\frac{2E(V_{o}-V) }{p}(\frac{1}{N_{A} }+\frac{1}{N_{D} })

If NA is greater, then, the term 1/NA can be neglected, thus the equation:

w=\sqrt{\frac{2E(V_{o}-V) }{p}(\frac{1}{N_{D} })

Where

V = 0.44 V

E = 11.68*8.85x10¹⁴ f/cm

V_{o} =\frac{KT}{p} ln(\frac{N_{A}*N_{D}}{n_{i}^{2}  } , if n_{i}=1.5x10^{10}cm^{-3}  \\V_{o}=0.02585ln(\frac{4.48x10^{18}*4.48x10^{15}  }{(1.5x10^{10})^{2}  } )=0.83V

w=\sqrt{\frac{2*11.68*8.85x10^{-14}*(0.83-0.44) }{1.6x10^{-19}*4.48x10^{15}  } } =3.35x10^{-5} cm=0.335um

The length is:

L = 10 - 0.335 = 9.665 um

The resistance is:

Re=\frac{pL}{A} =\frac{0.93*9.665x10^{-4} }{0.36x10^{-4} } =24.9ohm

7 0
3 years ago
Other questions:
  • A rectangular channel 2 m wide carries 3 m3 /s of water at a depth of 1.2 m. If an obstruction 40 cm wide is placed in the middl
    12·1 answer
  • What instrument is used to measure temperature?
    10·1 answer
  • The velocity of a point mass that moves along the s-axis is given by s' = 40 - 3t^2 m/s, where t is in seconds. Find displacemen
    7·1 answer
  • write an interface downloadable that has a method "geturl" that returns the url of a downloadable object
    5·1 answer
  • True or False; If I was trying to find the Voltage of my computer, and I was given the Watts and Amps it uses, I would use Watt'
    8·1 answer
  • The complexity of bfs and dfs
    11·1 answer
  • Cual es la definición de la distribución de las instalaciones?
    13·2 answers
  • PROBLEM IN PICTURE HELP ME DEAR GODDDDDD UGHHH NONONO I HAVE 2 MINUTES TO FINISH THIS ❕❗️❕❗️❗️❕❕❕❕❗️❕❕❗️❕❗️❗️❗️❕‼️‼️‼️‼️❗️‼️❗️
    11·2 answers
  • PDC Bank is working on creating an AI application that enables customers to send SMS to the AI application to allow banking acti
    9·1 answer
  • Why is communication one of the most important aspects of an engineer's job?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!