Write a C program to find the largest sequence of numbers in an array which sums to any given

number.

Example:

Consider an array: [1,2,3,5,6,7]

Given a number say 8.

Possible sequences: 3+5=8, 1+2+5=8, 2+6=8, 1+7=8, etc.

Output: (1,2,5)

Write a C program to find the largest sequence of numbers in an array which sums to any given

number.

Example:

Consider an array: [1,2,3,5,6,7]

Given a number say 8.

Possible sequences: 3+5=8, 1+2+5=8, 2+6=8, 1+7=8, etc.

Output: (1,2,5)

You joined this forum 10 minutes ago just to get ready made homework done by us!! Not happening.

No one will give you complete code but we can definitely help with the logic.

This looks like a slight variation of the subset sum problem which has an exponential solution and will work fine for upto 40 numbers.You will have to write a function and using recursion explore all possible subsets and then find the longest one among those. Here are more details on the subset sum problem. The subset sum is NP complete and i done think there will be an assymptotically better solution for this.

2 Likes

please help me to write the logic…

no1 here is going to do your homework…show some effort…atleast try a naive approach…then ask!!!

2 Likes