freelanceprogrammers.org Forum Index » C

Re: Finding the set of consecutive integers which sum up to


View user's profile Post To page top
kannadhasanm Posted: Thu Jan 06, 2005 7:01 pm


Joined: 06 Jan 2005

Posts: 2
Re: Finding the set of consecutive integers which sum up to
1. Finding the set of consecutive integers which sum up to the max Suppose we have a list of integers .. say [1,3,0.-4,5,4,-6,0,8,-5] ... Now, in this list, the group (4,5) can be called the set of consecutive integers that sums up to the max total (i.e, 9). Now how do we write a program for this? I was thinking on the lines of starting from 1 and summing up things. Then starting from 3 and summing up things... This does not seem to be efficient... 
Ans:  Just take the first two nos. and store in two variables, add it up, and store in 3rd variable, next consider 2nd & 3rd nos. add then compare with stored value, if new no is greater update the storing variable by new no.along with the two added numbers, continue with the consecutive integers list and at the end the group and the total can be achieved.
for the 2nd question I didn`t get the image, sorry.
-Kannadhasan.M kannadhasanm@...
 

Yahoo! India Matrimony: Find your life partner
online.
Reply with quote
Send private message
View user's profile Post To page top
matrixconquers Posted: Fri Jan 07, 2005 7:28 pm


Joined: 07 Jan 2005

Posts: 2
Re: Finding the set of consecutive integers which sum up to
hi,
herez the code
 int a[]={-23,-19,222,-113,-4,15,-13,-12,-1117,-3,18}; // jus for ex : int i=0,index1=i++, max=a[i-1]+a[i]; for(;i<=9;i++)     if(a[i]+a[i+1]>max)     {     index1=i;     max=a[i]+a[i+1];  }cout<<"Position: "<<index1<<" and "<<index1+1; cout<<"
Values: "<<a[index1]<<" and "<<a[index1+1];
kindly intimate me if there is any problem with the code
thanx
Do you Yahoo!? The all-new My Yahoo! – What will yours do?
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help