//CIS:610-251: Data Structures and Algorithms //Assignment#1: Sept 9,1999 //Object: Median of numeric Array #include #define nl "\n" main() { int numbers[255]; int outer=0,inner=0,temp=0,size=0; float median=0; // while(size<256) { cout << "\nEnter Integer # " << size+1 << " (-999999=end):" ; cin >> numbers[size]; if (numbers[size++]==-999999) {size--;break;} } //Select one item and compare it with the rest // if selected item is less then any of the rest swap it. if (size) { for(;outer numbers[outer]) { temp=numbers[inner]; numbers[inner]=numbers[outer]; numbers[outer]=temp; } //Calculate Median median= (size%2)? numbers[int(size/2)] : (float)(numbers[size/2]+numbers[size/2-1])/2; cout << nl << "Median of Numbers =" << median << nl; } else cout << "\nNo numbers Entered.\n"; return 0; }