hii I think this code will work
#include<stdio.h>
#include<string.h>
void largestsum(int a[],int n)
{
int s=0,e=0,ls=0,max=0,j,i,sum=0;
for(i=0;i<n;i++)
{
sum+=a[i];
if(sum>max)
{
max=sum;
e=i;
s=ls;
}
if(sum<0)
{
sum=0;
ls=i+1;
}
}
printf("\nlargest sum is=%d\n",max);
printf("The element which make largest sum is\t");
for(j=s;j<=e;j++)
{
printf("%d\t",a[j]);
}
}
int main() {
int a[]={6,4,-5,5,2,8,-21,15,4};
int n=9;
largestsum(a,n);
return 0;
}
Thanks & Regards
Sinjan
M.Tech(s/w engg)
DTU delhi
On Sep 17, 2:55 pm, prasanth n <[email protected]> wrote:
> given a matrix with +ve and -ve numbers, find the submatrix with maximum
> sum??
>
> --
> *prasanth*
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.