Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //function prototype
- void moveAndSortInt(int[], int);
- int main() {
- displayInfo();
- cout << "\n";
- int ary1[] = { -15, 450, 6, -9, 9 };
- int ary2[] = { 100, -15, 450, 6, -91, 9 };
- int size, i(0);
- size = 5;
- cout << "Original ary1[]\n";
- for (i = 0; i < size; i++) {
- cout << ary1[i] << " ";
- }
- cout << endl;
- cout << endl;
- moveAndSortInt(ary1, size);
- cout << "Calling moveAndSortInt() - -\n";
- cout << endl;
- cout << "Updated ary1[]\n";
- for (i = 0; i < size; i++) {
- cout << ary1[i] << " ";
- }
- cout << endl;
- cout << endl;
- size = 6;
- cout << "Original ary2[]\n";
- for (i = 0; i < size; i++) {
- cout << ary2[i] << " ";
- }
- cout << endl;
- cout << endl;
- moveAndSortInt(ary2, size);
- cout << "Calling moveAndSortInt() - -\n";
- cout << endl;
- cout << "Updated ary2[]\n";
- for (i = 0; i < size; i++) {
- cout << ary2[i] << " ";
- }
- cout << endl;
- cout << endl;
- system("pause");
- }
- // Fuction definition
- void moveAndSortInt(int ary[], int size) {
- int i, j, temp;
- for (i = 0; i < size; i++) {
- if (ary[i] % 2 == 0) {
- for (j = size - 1; j > 0; j--) {
- if (ary[j] % 2 != 0) {
- temp = ary[i];
- ary[i] = ary[j];
- ary[j] = temp;
- j = 0;
- }
- }
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement