How to make all possible sum combinations from array elements in VB

后端 未结 3 730
生来不讨喜
生来不讨喜 2021-01-24 06:51

If there is an array with elements: 1,2,3,4, the program should return another array with sum of all combinations:

1
2
3
4
3 (1+2)
4 (1+3) 
5 (1+4)
5 (2+3)
6 (2+4)
7 (         


        
3条回答
  •  故里飘歌
    2021-01-24 07:25

    My idea is:

    (pseudcode, I don;t know VB)

    for(int i = 0; i < 4321; i++)
    {
        i mod 10 + // first from right digit
        (int)((i mod 100)mod 10) // second, (?)
        // etc
        // sum up all 4 digit
        // add to array  
    }
    

提交回复
热议问题