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 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; }


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.


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


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])


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


Write a c program to reverse an array without using another array?

public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i < array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }


Write an Algorithm to delete a last element from the array?

// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;


The maximum number of records you might want to store in an array is defined as MAX When using 0 based indexing what index will reference the last allocated position of an array of size MAX?

If all elements of the array are in use then the last record is referred to as MAX-1. If you are using a count variable to remember how far into the array you are using then this variable will keep track of the last allocated value in the array.


How do you merge two array without using function?

Take another array big enough to hold both array copy content of these two array into new one. You merged two array and haven't used a single function.!


How do I put calculated numbers into an array using assembly programming language?

In assembly language, you can store calculated numbers into an array by first defining the array in the data segment using directives like .data or .section .data, followed by the array name and its size. After performing your calculations, use the appropriate registers to load the calculated values and store them in the array using the MOV instruction, specifying the array index for storage. For example, if you want to store a value in the first index, you can calculate the address of the array and use an offset for the specific index. Finally, ensure that you manage the array size and boundaries to avoid overflow.


Create a mark list using array with structure?

sorce code for student mark list usig array


How do you find matrix in c?

using multidimensional array


How do you flip an array without using flip function in PHP?

Use a for-loop starting at the length of the array and go backwards and build up a new array with the values.