I have no idea why suddenly the value of integer is changing even though there's no process of caluclation, here's the code of my program :
#include <iostream>
using namespace std;
int main()
{
int n;
int a[] = {};
int b[] = {};
cin >> n;
cout << "\n";
for(int i=0;i<n;i++)
cin >> a[i];
cout << "\n";
for(int i=0;i<n;i++)
cin >> b[i];
cout << "\n";
for(int i=0;i<n;i++)
cout << a[i] << " " << b[i] << "\n";
cout << n;
}
So if I input the value of n lower than 5, there's no problem with the code. But if I put the value of n higher than 4, the value of integer a[i] will follow the value of b[i] somehow and the value of n is different from what I input. As for example it's like this Input :
10
1
2
3
4
5
6
7
8
91
92
93
94
95
96
97
98
Output :
95 91
96 92
97 93
98 94
5 95
6 96
7 97
8 98
8
As you can see the value of n changing from 10 to 8, and the loop only happen for 8 times. Why the value of n and a[i] are changing? Any help is appreciated, thanks