Thread: Need help using Arrays

  1. #1
    Registered User
    Join Date
    Jan 2002

    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.


  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    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.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    and for the third question, you could try a bubble sort;

    #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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM