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-04T04:00:12-0500
#include <iostream> #include <conio.h>
using namespace std;
int getOddNumbers(int* inArr, int* outArr, int n) { int nOutArr = 0; for(int i=0; i<n; i++) { if(*(inArr+i)%2) { *(outArr+nOutArr) = *(inArr+i); nOutArr++; } } return nOutArr; }
int getEvenNumbers(int* inArr, int* outArr, int n) { int nOutArr = 0; for(int i=0; i<n; i++) { if(!(*(inArr+i)%2)) { *(outArr+nOutArr) = *(inArr+i); nOutArr++; } } return nOutArr; }
Comments
Leave a comment