Maximum subarray sum

sir what is the mistake in my code

#include
using namespace std;

int subarraysum(int n,int a[] )
{
int cs=0,ms=0;
for(int i=0;i<=n;i++)
{
cs=cs+a[i];
if(cs<0)
{
cs=0;
}
ms=max(cs,ms);
}
return ms;
}

int main()
{
int t,n,j,a[n],i;
cin>>t;
for(i=1;i<=t;i++)
{
cin>>n;

for(j=1;j<=n;j++)

{
cin>>a[i];

}

int s=subarraysum(n,a);
cout<<s<<endl;
}

}

The array must be declared within the loop for test cases. (Else it will carry forward the values of previous test case). Change that and then check.
If still there are some problems then save your code on ide.codingblocks.com and share its link.