View Code of Problem 19

#include<stdio.h>
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		if(n==0)
		  break;
		long int a[n],i,flag=0;
	    for(i=0;i<n;i++)
	    {
		   scanf("%d",&a[i]);
	    }
	
	   
	       int sum=-10000,b=0,i;
	       for(i=0;i<n;i++)
	       {
		      if(b>0)
		         b+=a[i];
		      else
		         b=a[i];
		      if(b>sum)
		         sum=b;
	        }
	         printf("%d\n",sum);
	 
	}	
}
/*
Main.c: In function 'main':
Main.c:12:6: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'long int *' [-Wformat=]
      scanf("%d",&a[i]);
      ^
Main.c:16:28: error: conflicting types for 'i'
         int sum=-10000,b=0,i;
                            ^
Main.c:9:17: note: previous declaration of 'i' was here
   long int a[n],i,flag=0;
                 ^
Main.c:9:19: warning: unused variable 'flag' [-Wunused-variable]
   long int a[n],i,flag=0;
                   ^
*/

Double click to view unformatted code.


Back to problem 19