Segmentation fault in max subarray problem

repeatedly getting segmentation fault error in max subarray problem

include < iostream>

using namespace std;

int main() {

int t;
cin>>t;
cout<<"t  = "<<t<<endl;

for(int j=0;j<t;j++){

	int n, sum = 0;

	cin>>n;

	int a[n];

	cout<<"n = "<<n<<endl;

	for(int i=0;i<n;i++)
		cin>>a[i];

	sum = a[0];

	for(int i=0;i<n;i++){
		if(a[i] > 0)
			sum = sum + a[i];
		//cout<<sum<<endl;
	}

	cout<<"sum = "<<sum<<endl;
}

return 0;

}

Where is the segmentation fault not able to spot it…

@stsavi09 you have made a successful submission do you still need assistance?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.