Need help using Arrays

• 01-07-2002
Boballica
Need help using Arrays
I am still kind of new to programming, and I need some help for school. I have three questions.1 I need to fill and array will double values that are entered from the keyboard, how do I fill the arrays and then stop at a flag value(I was thinking of using a do while loop). 2. How can I find the median of that array after it has been filled and determined to have an even or odd amount of numbers in it? 3. Still using the same array, how do I make it so that it is ordered in ascending order. I know this is a long post, but any and all help is greatly appreciated.

Boballica
• 01-07-2002
golfinguy4
1. Use for loops to go through every item in the array and the user can input the values for that item

2. multiply the dimensions, check if the product is odd by taking the product and %2. If 1 is returned, the number of items is odd.
• 01-07-2002
Fordy
and for the third question, you could try a bubble sort;

Code:

```#include <iostream> using std::cout; using std::endl; int main(void){         int array[4] = {3,9,1,5}, x;         int size = sizeof(array)/sizeof(int);         cout << "Unsorted\n";         for(x = 0;x < size;x++)cout << array[x] << '\t';         cout << endl;                 for(int pass = 0;pass < size-1;pass++){ //pass through each array member                 for(int sorter = 0;sorter < size-1; sorter++){                         if(array[sorter] > array[sorter+1]){ //test if bigger than next                                 int hold = array[sorter+1];                                 array[sorter+1] = array[sorter];                                 array[sorter] = hold; // if so, swap them                         }                 }         }         cout << "Sorted\n";         for(x = 0;x < size;x++)cout << array[x] << '\t'; return 0; }```
That's about the simplest sorting algo out there