0

Hi,

I have no1 to no30 product prices.
I want to calculate combination for 30 product prices

Suppose I have 30 different numbers..
I want to calculate their sum by using combination.

But combination should not repleted
i.e.
E.g
for 4 numbers...
[ 10 20 30 40]

I want to do like without repetition
10
20
30
40
10+20
10+30
10+40
20+30
20+40
30+40
10+20+30
10+20+40
10+30+40
20+30+40

so how to calculate 30 numbers in this way..without repetition
How to do that??
I think when i calculate sum without repetition for numbers it takes minimum time Or any algorithm or method to do it fast in minimum time??

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by rush1
0

Firstly get the input in an array.

After that you can use a recursive function which takes in an element of an array and then only adds elements in front of it till the array ends.

Another thing is you should specify the number of elements that you wish to take to the function.

Provided n elements in the array.

I guess you can write a recursive function.
If you need more help. Just post in the code and doubts.

0

hi Sky Diploma,

Can you give me sample code??

for (i=0;i<=count;i++)
{
      printf("%d", &List[i]);
}

ouput
10 20 30 40
I have done in my 1st step .
plz guide me for further steps..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.