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??

Recommended Answers

All 2 Replies

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.

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.