answersLogoWhite

0

public static final double getAverage(final int[] ns) {

if (ns.length == 0) {

return 0.0;

}

int sum = 0;

for (int n : ns) {

sum += n;

}

return ((double) sum) / ns.length;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Queue ADT Using Array?

implement the queue ADT using an array


Why and is not using ' and ' in reading a string using scanf?

I guess you wanted to ask, why is it scanf ("%s", array)and not scanf ("%s", &array).Well, array is by definition a pointer to the first element: array = &array[0]


What is need to array?

Because using array you can easily access the data required


How do you display 15 numbers in an ascending order using an array?

Sort the array then traverse the array, printing the element values as you go.


How do you write a c plus plus program that will average 10 numbers entered and print the array?

#include<iostream> #include<sstream> #include<vector> using namespace std; int main() { vector<int> Array; for (size_t index=0; index<9; ++index) { int i; bool valid = false; while (!valid) { cout << "Enter a number: "; string input; cin >> input; stringstream ss; ss << input; valid = (ss >> i); if (!valid) cout << "Invalid input.\n"; } Array.push_back (i); } // print array and average int average=0; for (size_t index=0; index<9; ++index) { cout << Array[index] << ' '; average += Array[index]; } average /= 10; cout << "\nAverage: " << average << endl; }


What is the syntax for determining the size of an array in C using the keyword sizeof?

To determine the size of an array in C using the keyword sizeof, you would use the syntax: sizeof(array) / sizeof(array0).


How do you print element in array using javascript?

You would insert this command right after your array values have been specified.document.write(name of array[Number on array this item is, starts at 0])


How can you find factorial of each element in array using pointer?

To find the factorial of each element in an array using pointers in C, you can create a function that takes a pointer to the array and its size as parameters. In the function, iterate through the array using pointer arithmetic, calculating the factorial for each element and storing the result back in the same array or a separate array. For calculating the factorial, you can use a simple loop or recursion. Finally, print or return the modified array with the factorials.


Sort array in ascending descending order in python?

Using sorted(array,reverse=True)


How do you find particular element in array?

by using index position we can find the particular element in array.


How do you count the vowels in a string using PHP?

build an array of vowels then do a foreach on the array and then explode the string on the array value and the answer is -1 of the result


Can you implements tree using array?

yes you can....