you need to add the same values from the first and second arrays to the array, it seems that the values are entered, but when the third array is output, the "garbage values" are output
#include <iostream> #include <time.h> using namespace std; void main() { const int size = 10, size1 = 20; int massA[size], massB[size], massC[size1]; srand(time(NULL)); for (int i = 0; i < size; i++) { massA[i] = rand() % 10; cout << massA[i] << " "; } cout << endl; for (int i = 0; i < size; i++) { massB[i] = rand() % 10; cout << massB[i] << " "; } for (int z=0, i = 0; z<size, i < size; i++,z++) { for (int j = 0; j < size; j++) { if (massA[i] != massB[j]) { massC[z] = massA[i]; cout << massA[i] << " "; } } } for (int i = 0; i < size1; i++) { cout << massC[i] << " "; } system("pause"); }
-858993460
is represented as hex, then you get0xCCCCCCCC
, which usually indicates that the memory is not initialized. In different systems in different ways. - αλεχολυτfor (int z=0, i = 0; z<size, i < size; i++,z++)
- complete and absolute duplication ofi
andz
? - Harry