Write a program that takes input of 10 integers into an array.
Give two options to the user:
1= copy odd numbers from the array to a new array (odd[] array) and sort “odd[]” array in ascending order
and
2= copy even numbers from the array to a new array (even[] array) and sort “even[]” array in ascending order
Write a function that accept (odd[] or even[]) array and sort it
Use bubble sort technique to sort the given array
Display the sorted array.
1
Expert's answer
2016-12-04T03:59:10-0500
#include <iostream> #include <cstdlib>
#define SIZE 10
using namespace std;
void printArray(int array[], int size) { int last = size - 1;
for (int i = 0; i < last; i++) { cout << array[i] << ' '; } cout << array[last] << endl; }
void sortArray(int array[], int size) { int len = size - 1; bool swapped = false;
for ( int j = 0; j < len && !(swapped); j++ ) { swapped = true; for ( int i = 1; i < size - j; i++ ) { if ( array[i-1] > array[i] ) { int swap = array[i-1];
Comments
Leave a comment