Question

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, –2, 4, –4, 9, –6, 16, –8, 25, –10], your method should return approximately 11.237.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//C code
float standardDeviation(int arr[], int n) {
   int i;
   float res = 0;
   float m = 0;
   for (i = 0; i<n; i++) {
      m += arr[i];
   }
   for (i = 0; i<n; i++) {
      res += pow(arr[i] - m, 2);
   }
   return (float)sqrt(res / (n - 1));
}

Add a comment
Know the answer?
Add Answer to:
Write a method called stdev that returns the standard deviation of an array of integers. Standard...
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
  • How do you find standard deviation once you know variance? a. take the square root of...

    How do you find standard deviation once you know variance? a. take the square root of variance b. square variance c. they are the same d.Variance minus 1 equals standard deviation This is the equation for population variance ______ a. Sum of Squares divided by N SS/N b. Sum of Squares divided by N plus one SS/N+1 c. Sum of Squares divided by N minus one SS/N-1 d. It is the same for sample variance You would use this equation...

  • How to write a recursive method named lessThanKFirst that receives an array of integers a and...

    How to write a recursive method named lessThanKFirst that receives an array of integers a and an integer k and rearranges the integers in a in such a way that all integers that are smaller than k come before any integers that are greater than or equal to k. As an example, suppose that a and k are: int[] a  = {35, 12, 57, 28, 49, 100, 61, 73, 92, 27, 39, 83, 52}; int k = 73; Then, the following...

  • Write a program that initializes an array with ten random integers and then prints out the...

    Write a program that initializes an array with ten random integers and then prints out the following: Every element at an even index; Every even element All elements in reverse order; Only the first and last elements; The minimum and maximum element The sum of all elements The alternating sum of all elements, where the alternating sum contains all elements at even index added, and the elements at odd index subtracted. Please write comments above the piece of code that...

  • 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...

  • Write a JAVA program with methods that initializes an array with 20 random integers between 1...

    Write a JAVA program with methods that initializes an array with 20 random integers between 1 and 50 and then prints four lines of output, containing 1)The initialized array. 2)Every element at an even index. 3)Every even element. 4)All elements in reverse order. Requirements (and hints): 1. Build a method that takes any integer array as input and prints the elements of the array. ALL printing in this lab must be done using a call to the printArray method and...

  • Implement the selfDot method below, which takes as input an array of integers and returns the...

    Implement the selfDot method below, which takes as input an array of integers and returns the sum of the each of the elements squared. An example main method, as well as corresponding output, is supplied - you cannot this method, and the output when the program is run must conform exactly to the sample output./* sample run: 14 125 */public static void main(String args[]) {int nums1[] = {1, 2, 3}; int nums2[] = {10, 5}; System.out.println(selfDot(nums1));//1*1 + 2*2 + 3*3...

  • Someone help please Let A be an array of 5 integers, whose contents are as follows:...

    Someone help please Let A be an array of 5 integers, whose contents are as follows: 3, 2, 1, 5, 4 We will apply quick sort to sort this array. Show all of the element-wise comparisons made by the algorithm in the correct order. Here an element-wise comparison means the comparison of one element of the array with another element of the array or the key set in a particular step of the algorithm. Since the algorithm may move the...

  • 1. Write a static method named mode that takes an array of integers as a parameter...

    1. Write a static method named mode that takes an array of integers as a parameter and that returns the value that occurs most frequently in the array. Assume that the integers in the array appear in sorted order. For example, if a variable called list stores the following values: ist -3, 1, 4, 4, 4, 6, 7,8, 8, 8, 8, 9, 11, 11, 11, 12, 14, int 141i Then the call of mode (li array, appearing four times. st,...

  • A java exercise please! Write a static method named swapHavles that takes an ArrayList of integers...

    A java exercise please! Write a static method named swapHavles that takes an ArrayList of integers as a a parameter and returns a new ArrayList that has every element in the second half of the original ArrayList swapped with every element in the first half of the original ArrayList. Note: • You can assume that the ArrayList passed to this method as a parameter always contains an even number of elements and will always contain at least two elements. For...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

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
ADVERTISEMENT