Hello, I was assigned to make this program that it's really easy of first inputing a number(m) to find 2 numbers numbers that when they sum, they equal to m. Then input another number(n) which is the number of numbers that u will input to find if they sum m. Then input the n numbers and display all the pairs that sum m.
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main(int argc, char *argv[])
{
longint A[1000000], m, n;
cin>>m;
cin>>n;
for (int x=1; x<=n; x++){
cin>>A[x];
}
for (int a=1; a<=n; a++){
for (int b=a+1; b<=n; b++){
if (A[a]+A[b]==m){
cout<<A[a]<<" "<<A[b]<<endl;
}
}
}
string trash;
getline(cin, trash);
getline(cin, trash);
return EXIT_SUCCESS;
}
The question here is that it that the maximum value of n can be 1 million, the code works fine, but when I use an array of 1 million, the program compiles and when the black window opens, an error message is displayed. Is this a data type thing? Because i have been using long int and it doesn't work neither. Help Please
Stack size is limited. Arrays are allocated on the stack. Allocate memory on the heap with new, or make your life easier and use a vector. http://cplusplus.com/reference/stl/vector/