0
Sum of all subarray
int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int curr=0; for(int j= i;j<n;j++){ curr+=a[j]; cout<<a[j]<<endl; } return 0; } Error: I is not declared in this line(for(int j= i;j<n;j++))
5 Réponses
+ 3
Hey there soni singh ,
Please add/put your code in the code playground and then link it, so that we cam help you more easily :)
https://www.sololearn.com/post/75089/?ref=app
+ 1
You are trying to assign the value of 'i' to the loop variable 'j', but 'i' is local to its own loop and therefore not accessible on the outside. You could move its declaration out of the loop, but that would still make little sense as it would equal 'n' at the end, resulting in the second loop not running.
What elements of the array are you trying to sum up?
+ 1
soni singh That is not very helpful. We can't assist you if you don't work with us.
0
J
0
a[j]