#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>> n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
cout<<a[j]<<" ";
}
cout<<endl;
}
int sum=0;
int mx=INT_MIN;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
for(int k=i;k<=j;k++)
sum += a[k];
mx = max(mx,sum);
cout<<endl;
}
}
}
cout<<mx;
return 0;
}
The compiler gives these three errors.
MaxSubArrSum.cpp:40:5: error: 'cout' does not name a type
40 | cout<<mx;
| ^~~~
MaxSubArrSum.cpp:41:5: error: expected unqualified-id before 'return'
41 | return 0;
| ^~~~~~
MaxSubArrSum.cpp:42:1: error: expected declaration before '}' token
42 | }
| ^
I feel the third issue will resolve on its own if the second one gets addressed? The quoting of cout and return suggests that it is a general syntax error. I've tried to keep my code as clean as possible by putting spaces and brackers appropriately though.