@prasanth : sinjalspecial is correct bt his code works for 1D array . for 2D array you can think of array of 1D array and then implement the same . newazz here is one link : http://tech-queries.blogspot.com/2010/05/find-max-sum-in-2d-array.html
On Sat, Sep 17, 2011 at 8:43 PM, tech coder <[email protected]>wrote: > people just dont read the question properly and post the answer > > On 9/17/11, prasanth n <[email protected]> wrote: > > @sinjanspecial: > > > > i think your code is for an 1 D matrix..but i have to find for a 2D > matrix.. > > > > On Sat, Sep 17, 2011 at 7:33 PM, sinjanspecial > > <[email protected]>wrote: > > > >> 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. > >> > >> > > > > > > -- > > *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. > > > > > > > -- > * > > Regards* > *"The Coder"* > > *"Life is a Game. The more u play, the more u win, the more u win , the > more > successfully u play"* > > -- > 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. > > -- 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.
