I have two arrays array1 of size 3 and array2 of size 2. I wish to form a pair of each item from both arrays. That is;
int array1[] = {1, 2, 3};
int array2[] = {9, 4};
Results I'm hoping to achieve:
1 , 9
1 , 4
2 , 9
2 , 4
3 , 9
3 , 4
This is what I have tried:
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
int array1[] = {1, 2, 3};
int array2[] = {9, 4};
int arrayOneSize = sizeof(array1);
int arrayTwoSize = sizeof(array2);
for (size_t i = 0; i < arrayOneSize; i++)
{
for (size_t j = 0; j < arrayTwoSize; j++)
{
cout << array1[i] << " , " << array2[j] << endl;
}
}
return 0;
}
But for some reason I am getting a whole bunch of weird combinations like:
1,9
1,4
1,1
1,2
1,3
1,1029505037
1,-531587312
... (It's really long, just want to shorten the results a little)
0,-411331072
1,9
1,4
1,1
1,2
1,3
1,1029505037
1,-531587312
1,-411331072
Sorry for the noob question. I am still new to C++ so, I will gladly appreciate any help. And also why am I getting numbers which are not part of the array?
Thanks in advance.