what is the mistake in my code
What is the mistake in my code
#include
using namespace std;
int main()
{
int t ;
cin >>t;
while(–t)
{
int a[100],n;
int c_sum,max1;
c_sum = max1 = 0;
cin >>n;
for(int i = 0;i < n;i++)
cin>>a[i];
for(int i = 0;i < n;i++)
{ c_sum = c_sum + a[i];
if(c_sum < 0)
c_sum = 0;
max1 = max(max1,c_sum);
}
cout <<max1;
}
}
hey @shiva57reddy, do the folleing changes
- just do post decrement of varible t instead of predecrement.
- change datatype to long int or long long int.
- increase the size of array to 100000
- put endl when you are printing the answer.
Updated code https://ide.codingblocks.com/s/106337