Ok, so when I am printing the final array (arr2), the first element that has been copied from odd[] to arr2[] is a random number instead of it being an odd number that was inserted in arr1[]. Here's a picture as an example pic .
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int arr[20], odd[20],arr2[20], i, j = 0, k = 0, no,temp,temp2,o=1;
cout << "Size of Array: ";
cin >> no;
cout << "Enter any " << no << " elements in Array: ";
for (i = 0; i<no;i++)
{
cin >> arr[i];
}
for (i = 0; i<no;i++)
{
if (arr[i] % 2 == 0)
{
arr2[j] = arr[i];
j++;
temp = j+1;
}
else
{
odd[k] = arr[i];
k++;
temp2 = k;
}
}
cout << endl;
cout << "New array:" << endl;
for (i = 1; i <= temp2; i++)
{
arr2[temp] = odd[o];
temp++;
o++;
}
for (i = 0;i < no;i++)
{
cout << arr2[i] <<endl;
}
}