Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

You're given an array containing both positive and negative
integers and required to find the sub-array with the largest
sum (O(N) a la KBL). Write a routine in C for the above.

Answer Posted / gopika

main()
{
int arr[100],sz,i,max,j,k,sum;
int start,end;
printf("\nEnter size :");
scanf("%d",&sz);
printf("\nEnter elements : ");
for(i=0;i<sz;i++)
scanf("%d",&arr[i]);

max=arr[0];

for(j=1;j<=sz;j++)
for(i=0;i<sz-j+1;i++)
{ sum=0;
for(k=0;k<j;k++)
{
sum+=arr[i+k];
if(sum>max)
{
max=sum;
start=i;
end=i+k;
}

}
}

printf("\nMax is %d\nStart %d\nend %d",max,start,end);
getch();
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If all is successful, what should main return a) 0 b) 1 c) void

1001


What is the most useful programming language?

1033


What is the difference between ++ count and count ++?

1130


What is ios flag in c++?

1192


In c++, what is the difference between method overloading and method overriding?

1121


Is c++ faster than c?

1007


What is #include iostream h in c++?

1146


what is scupper?

2373


what are Operators and explain with an example?

1148


How to defines the function in c++?

1109


Does c++ have a hash table?

981


Explain polymorphism?

1066


What is a hashmap c++?

1102


What do you mean by early binding?

1051


Define a constructor?

1038