How would I transform the following program to allow the user toinputan odd number of positive integers in a single line (space-separated). In other words, how would I change the array to allow user input? The program should output the number that occurs the odd number of times.
Code to be Modified:
#include using namespace std;int getNumOccurredOdd(int arr[], int n) { int res = 0; for (int i = 0; i < n;=""> res = res ^ arr[i]; return res;}int main() { int arr[] = {3, 4, 6, 5, 6, 3, 5, 4, 6, 3, 5, 5, 3}; int n = sizeof(arr)/sizeof(arr[0]); cout < getnumoccurredodd(arr,="" n)="">< "="" is="" present="" odd="" number="" of="">}
using namespace std;
int getNumOccurredOdd(int arr[], int n) {
int res = 0;
for (int i = 0; i < n;="">
res = res ^ arr[i];
return res;
}
int main() {
int arr[] = {3, 4, 6, 5, 6, 3, 5, 4, 6, 3, 5, 5, 3};
int n = sizeof(arr)/sizeof(arr[0]);
cout < getnumoccurredodd(arr,="" n)="">< "="" is="" present="" odd="" number="" of="">
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here