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;
}
implement the queue ADT using an array
Sort the array then traverse the array, printing the element values as you go.
Using sorted(array,reverse=True)
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.!
sorce code for student mark list usig array
implement the queue ADT using an array
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]
Because using array you can easily access the data required
Sort the array then traverse the array, printing the element values as you go.
by using index position we can find the particular element in array.
Using sorted(array,reverse=True)
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])
#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; }
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
yes you can....
// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;
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; }