Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Exercise9SumOfSubsetIs0
- {
- static void Main()
- {
- int[] input = new int[5];
- for (int i = 0; i < 5; i++)
- {
- bool checkInput = false;
- while (!checkInput)
- {
- Console.Write("\nPlease input integer N{0}: ", i + 1);
- checkInput = int.TryParse(Console.ReadLine(), out input[i]);
- if (checkInput)
- {
- continue;
- }
- Console.WriteLine("\nWrong input data, try again!");
- }
- }
- Console.WriteLine("\n\n\nSets with sum equal to zero:\n");
- for (int position = 0; position < 5; position++)
- {
- for (int setSize = 2; setSize <= 5; setSize++)
- {
- if ((position + setSize) <= 5)
- {
- switch (setSize)
- {
- case 2:
- {
- if ((input[position]+input[position+1]) == 0)
- {
- Console.WriteLine("\nThe sum of set {0}, {1} is equal to zero!" ,input[position], input[position+1]);
- }
- }
- break;
- case 3:
- {
- if ((input[position] + input[position + 1] + input[position + 2]) == 0)
- {
- Console.WriteLine("\nThe sum of set {0}, {1}, {2} is equal to zero!", input[position], input[position + 1], input[position + 2]);
- }
- }
- break;
- case 4:
- {
- if ((input[position] + input[position + 1] + input[position + 2] + input[position + 3]) == 0)
- {
- Console.WriteLine("\nThe sum of set {0}, {1}, {2}, {3} is equal to zero!", input[position], input[position + 1], input[position + 2], input[position + 3]);
- }
- }
- break;
- case 5:
- {
- if ((input[position] + input[position + 1] + input[position + 2] + input[position + 3] + input[position + 4]) == 0)
- {
- Console.WriteLine("\nThe sum of set {0}, {1}, {2}, {3}, {4} is equal to zero!", input[position], input[position + 1], input[position + 2], input[position + 3], input[position + 4]);
- }
- }
- break;
- }
- }
- }
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement