I have a task to print all zero subsets of 5 numbers, input from the console.I have succeeded in implementing a working code, but it seems it is quite complex (it is like inception) and if the count of the numbers is to be greater, it would be rather pointless to use such a method.using System;using System.Collections.Generic;using System.Linq;class ZeroSubset{    static void Main()    {        int number;        int[] Numbers = new int[5];        bool result = false;        for (int i = 0;i <=4; i++)        {            here: ;            Console.WriteLine(Input number {0}, i + 1);            if (int.TryParse(Console.ReadLine(), out number))            {                Numbers[i] = number;            }            else            {                goto here;            }        }        if (Numbers[0] == 0 && Numbers[1] == 0 && Numbers[2] == 0 && Numbers[3] == 0 && Numbers[4] == 0)        {            result = true;            Console.WriteLine(String.Join(+, Numbers) +  = 0);            return;        }        for (int firstNum = 0; firstNum <= 3; firstNum++)        {            for (int secondNum = firstNum + 1; secondNum <= 4; secondNum++)            {                if (Numbers[firstNum] + Numbers[secondNum] == 0)                {                    result = true;                    Console.WriteLine({0} + {1} = 0, Numbers[firstNum], Numbers[secondNum]);                }            }        }         for (int firstNum = 0; firstNum <= 2; firstNum++)         {            for (int secondNum = firstNum + 1; secondNum <= 3; secondNum++)            {                for (int thirdNum = secondNum + 1; thirdNum <= 4; thirdNum++)                {                    if (Numbers[firstNum] + Numbers[secondNum] + Numbers[thirdNum]== 0)                    {                        result = true;                        Console.WriteLine({0} + {1} + {2} = 0, Numbers[firstNum], Numbers[secondNum], Numbers[thirdNum]);                    }                }            }        }        for (int firstNum = 0; firstNum <= 1; firstNum++)        {            for (int secondNum = firstNum + 1; secondNum <= 2; secondNum++)            {                for (int thirdNum = secondNum + 1; thirdNum <= 3; thirdNum++)                {                    for (int fourthNum = thirdNum + 1; fourthNum <= 4; fourthNum++)                    {                        if (Numbers[firstNum] + Numbers[secondNum] + Numbers[thirdNum] + Numbers[fourthNum]== 0)                        {                            result = true;                            Console.WriteLine({0} + {1} + {2} + {3} = 0, Numbers[firstNum], Numbers[secondNum]                                    , Numbers[thirdNum], Numbers[fourthNum]);                        }                    }                }            }        }        if (Numbers.Sum() == 0)        {            result = true;            Console.WriteLine(String.Join(+, Numbers) +  = 0);        }        if (result == false)        {            Console.WriteLine(no zero subsets);        }    }}I am asking for a more simple approach to this matter.
Sum of subset of 5 numbers equals 0
c#;array;console
As soon as I see a goto I get nostalgia, and know that you haven't taken a step back from this program and considered a world without goto (java). There is always a way to avoid using a goto, and this is a rather simple one with multiple alternatives which don't kill your program flow.I think the best one for your situation though is to only increment up when the TryParse is successful.for (int i = 0; i < Numbers.Length;){    Console.WriteLine(Input number {0}, i + 1);    if (int.TryParse(Console.ReadLine(), out number))        Numbers[i++] = number;}EDIT: Changed to add additional alternative that does not include i in the fail-success of the parse logic. for (int i = 0; i < Numbers.Length; i++){    for(bool done = false; !done;)    {        Console.WriteLine(Input number {0}, i + 1);        done = int.TryParse(Console.ReadLine(), out number);    }    Numbers[i] = number;}Note: I used < Numbers.Length, this way if you ever increase the size of the array, you can support more numbers without having to re-write this part.Next we can simplify some of your code with linq, which you should use any time you want to repeatedly do something to a list. Below, using linq, I query the list of numbers and I ask if all of them equal 0. if (Numbers.All(n => n == 0)){    Console.WriteLine(String.Join(+, Numbers) +  = 0);    return;}Also note that I removed you setting result = true, because you were not using that since your were returning right away.Naming convention: All of your method level variables should start with a lowercase letter, be camelCase, ie. numbers vs NumbersYour program is a bit flawed. Technically just 0 is a subset of {0,1,2,3,4} however you appear to only care of subsets of 2 or more numbers.A good alternative to your current implementaiton would have been to create a recursive function which takes in int[] remainingNumbers, int[] currentComposite, and the method would simply loop over the remainingNumbers and making new composites to check on, each time you would want to check just the currentComposite to see if that is a valid set.The way I would do it, would be to create a list of number arrays which hold every combination of the given numbers, then I would simply loop over that collection to determine which sets fit my conditions.Here is some code I found online (specifically here), because I did not want to make my own Combination generator. I'm going to post this code on CR, because I'd like to see someone take a stab at making it better.static List<List<int>> Combinations(int[] array, int startingIndex = 0, int combinationLenght = 2){    List<List<int>> combinations = new List<List<int>>();    if (combinationLenght == 2)    {        int combinationsListIndex = 0;        for (int arrayIndex = startingIndex; arrayIndex < array.Length; arrayIndex++)        {            for (int i = arrayIndex + 1; i < array.Length; i++)            {                combinations.Add(new List<int>());                combinations[combinationsListIndex].Add(array[arrayIndex]);                while (combinations[combinationsListIndex].Count < combinationLenght)                {                    combinations[combinationsListIndex].Add(array[i]);                }                combinationsListIndex++;            }        }        return combinations;    }    List<List<int>> combinationsofMore = new List<List<int>>();    for (int i = startingIndex; i < array.Length - combinationLenght + 1; i++)    {        combinations = Combinations(array, i + 1, combinationLenght - 1);        for (int index = 0; index < combinations.Count; index++)            combinations[index].Insert(0, array[i]);        for (int y = 0; y < combinations.Count; y++)            combinationsofMore.Add(combinations[y]);    }    return combinationsofMore;}Now just use some linq to only grab results from the Combinations function where the sum of the numbers in the list equates to 0. Foreach of them, print it to the console.foreach(var list in Combinations(Numbers).Where(list=> list.Sum() == 0))    Console.WriteLine(string.Join( + , list) +  = 0);I see that at the bottom of your code you are checking to see if all the values in Numbers are 0, and then printing a message, and returning. Why? You did this earlier, and had an early return, so if that was the case the code should never have made it here.