namespace CombinationWork
{
class Program
{
static void Main(string[] args)
{
List<int> List = new List<int>(new int[] {1,2,5,10});
for (int noSelected=0;noSelected<4;noSelected++)
{
for(int noAdded=0;noAdded<4;noAdded++)
{
List.Add(List[noSelected]+List[noAdded]);
}
}
List = List.Distinct().ToList();
for (int display = 0; display < List.Count; display++)
{
Console.WriteLine( List[display]);
}
Console.ReadLine();
}
}
}
Guys assistance needed. let say i have an array: int[] a={1,2,5,10}; I want to add all the elements with each other .Example:
- 1
2
2+1=3
- 5+1=6
- 5+2=7
- 5+2+1=8
- 10
- 10+1=11
- 10+2=12
- 10+2+1=13
- 10+5=15
- 10+5+1=16
- 10+5+2=17
- 10+5+2+1=18
I'm getting some inaccurate values. The error lies in using the nested for loops but i dont know what else to use