0
Can someone tell me what's wrong with my program?
#include <iostream> #include <math.h> using namespace std; int main() { int N,i=0,j=1; int m=0,p=1,max,max2=1; cin>>N; int a[N]; for (;i<N;i++) cin>>a[i]; max=abs(a[i]-a[j]); for (;i<N;i++) for (;j<N-1-i;j++) { if(abs(a[i]-a[j+1])>=max) { m=i; p=j+1; if(abs(m-p)>max2) max2=abs(m-p); max =abs(a[i]-a[j+1]); } } cou
1 Answer
+ 4
You cannot declare a non-constant value to the size of an array.
int a[N];
since N is not a constant, as it is input by the user, here is the error.
If you need dynamic groups of data, use a vector.
(Also, the random "cou" at the end, but I'm sure that's a typo).