Question

IN C# Write a method that is passed an array of doubles. Assume the array is...

IN C#

Write a method that is passed an array of doubles. Assume the array is completely full.
The method must return the average of the values in the array but leave out the maximum value.
Do not use any built-in methods or lambda expressions : just basic array processing code.

Example: array has 1.5, 1.5, 200, 1.5, 1.5, 200 then the method returns 1.5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This program is all about basic array operations such as finding maximum value and finding average and using condtional statements...

The executable code of the above problem is:

#include <stdio.h>
#include <stdlib.h>
double avg_excluding_max(double arr[],int n);/*function declaration*/
int main()
{
    double arr[100],avg;/*declaring array and average with double data type*/
    int n,i;
    printf("enter the length of the array:");
    scanf("%d",&n);
    printf("enter array elements\n");
    for(i=0;i<n;i++)
    {
       scanf("%lf",&arr[i]);/*entering elements into the array...note:lf is format used for double values*/
   }
   avg=avg_excluding_max(arr,n);/*this function returns a double value to hold that we use avg of double datatype*/
  
   printf("average of numbers in the array after excluding maximum value is:%lf",avg);
  
}
double avg_excluding_max(double arr[],int n)/*this is the actual function that finds the average of numbers in the array excluding maximum values*/
{
   double max=0,sum=0;
    int i,k=0;
    for(i=0;i<n;i++)/*this loop is for finding maximum value*/
    {
       if(max<arr[i])
       {
           max=arr[i];
       }
   }
   for(i=0;i<n;i++)
    {
       if(max!=arr[i])/*this condition statement is used to exclude the maximum value..*/
       {
          
           sum=sum+arr[i];/*adding array elements except maximum element*/
       }
       else
       {
           k++;/*this counts how many elements that are excluded,while calculating sum*/
       }      
   }
    return sum/(n-k);/*returning the average by dividing sum of observations/no of observations(excluding maximum numbers)*/
}

sample output1:

sample output2:

Add a comment
Know the answer?
Add Answer to:
IN C# Write a method that is passed an array of doubles. Assume the array is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Do the following: - Write and test a function that takes an array of doubles and...

    Do the following: - Write and test a function that takes an array of doubles and returns the average of the values in the array - Write and test a function that takes an array of doubles and returns number of values in the array that are above the average of the values in the array - Write and test a function that takes an array of Strings and returns number of values in the array that start with an...

  • Write a method that takes in a two-dimensional array of integers, do some calculation for each...

    Write a method that takes in a two-dimensional array of integers, do some calculation for each row in the two-dimensional array, and returns a one-dimensional array of sums for each row. Your code must work any array dimensions, including jagged arrays. The calculations are: • Sum of each row • Maximum value of each row • Minimum value of each row • Average of each row Here is an example an array passed and returns an array of sums for...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • 11) Write a method (including header and body) that takes as an input an array of...

    11) Write a method (including header and body) that takes as an input an array of doubles and f three doubles containing the average, the maximum and the minimunm values of the input array. Test the program by calling the method from the main method. For example Input: 1 2 3 45 Output: 3 5 1 12) Write a Java method that takes a string as an argument and returns the reverse the string. Test the program by calling the...

  • java pseudocode and source code help? Write a program that uses an array of high temperatures...

    java pseudocode and source code help? Write a program that uses an array of high temperatures for your hometown from last week (Sunday - Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array...

  • A method stub, or signature, is the first line of a method. Write a class that...

    A method stub, or signature, is the first line of a method. Write a class that contains the following “stubs” for methods used in measurement conversion. You do not have to implement the methods. Correct response: public void showMeters(int numMillimeters){} Write a method that takes two integers and displays their sum. Write a method that takes five doubles and returns their average. Write a method that returns the sum of two randomly generated integers. Write a method that takes three...

  • Write a method called stdev that returns the standard deviation of an array of integers. Standard...

    Write a method called stdev that returns the standard deviation of an array of integers. Standard deviation is computed by taking the square root of the sum of the squares of the differences between each element and the mean, divided by one less than the number of elements. (It's just that simple!) More concisely and mathematically, the standard deviation of an array a is written as follows: stdev(a)=∑i=0a.length−1(a[ i ]−average(a)2)a.length−1 For example, if the array passed contains the values [1,...

  • In JAVA: Write a method that reverses the array passed the argument and returns this array....

    In JAVA: Write a method that reverses the array passed the argument and returns this array. Write a test program that prompts the user to enter ten numbers, invokes the method to reverse the numbers and display the numbers. Write a method that returns a new array by eliminating the duplicate values in the array using following method header: a. Public static int[] eliminateDuplicates(int list) b. Write a test program that reads in ten integers and invoke the method, the...

  • /** * Write a method named outOfOrder that takes as a parameter an array of double...

    /** * Write a method named outOfOrder that takes as a parameter an array of double and returns a value of type int. * This method will test the array for being out of order, meaning that the array violates the conditions: * array[0] <= arrayValues[0] <= arrayValues[2] <=... * * The method returns -1 if the elemnts are not out of order; otherwise , it returns the index of the first element of the array that is out of...

  • CST-117 In-Class Assignment 7 A method stub, or signature, is the first line of a method....

    CST-117 In-Class Assignment 7 A method stub, or signature, is the first line of a method. Write a class that contains the following “stubs” for methods used in measurement conversion. You do not have to implement the methods. Here’s an example: Write a void method that takes an integer for the number of millimeters and displays the number of meters. Correct response: public void showMeters(int numMillimeters){} Write a method that takes two integers and displays their sum. Write a method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT