0
please help me compiling this c++ source code
i am working on a project in which the program takes the length of array from, you then took aray from you and then print the sum of the the elements of the corresponding array heres the code ; #include<iostream> #include<stdlib.h> #include<string.h> using namespace std; int N; int a[N]; void Arraysum() { int count = 0; int i=0; for(int j=0;j<N;j++) count+=a[i+j]; } int main() { cin>>N; for(int p=0;p<N;p++) cin>>a[p]; Arraysum(); cout<< count; return 0; }
2 Antworten
+ 2
Arraysum should be given parameters off argument array and N which is used and not defined, that should solve it, and you do not define the array
void Arraysum(int arr[], int N) does should be parameters
Arraysum(a,N) and here goes the argument
0
As *AsterisK* said, you should pass the array and N as argument to Arraysum. And you should declare the array after the input of N.
Here's the working code:
https://code.sololearn.com/cItyEWDYgHC5/?ref=app