Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CheckSumOfSubsets
- {
- static void Main()
- {
- Console.WriteLine("Please insert the five members of the set.\n");
- string consoleInput;
- Console.Write("a: ");
- consoleInput = Console.ReadLine();
- int a = int.Parse(consoleInput);
- Console.Write("b: ");
- consoleInput = Console.ReadLine();
- int b = int.Parse(consoleInput);
- Console.Write("c: ");
- consoleInput = Console.ReadLine();
- int c = int.Parse(consoleInput);
- Console.Write("d: ");
- consoleInput = Console.ReadLine();
- int d = int.Parse(consoleInput);
- Console.Write("e: ");
- consoleInput = Console.ReadLine();
- int e = int.Parse(consoleInput);
- Console.WriteLine();
- byte counter = 0;
- //Checking for the whole set
- if (a + b + c + d + e == 0)
- {
- Console.WriteLine("The sum of the whole set is zero!");
- counter++;
- }
- //Checking every subset of two members
- if (a + b == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a) and {1}(b) is 0", a, b);
- }
- if (a + c == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a) and {1}(c) is 0", a, c);
- }
- if (a + d == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a) and {1}(d) is 0", a, d);
- }
- if (a + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a) and {1}(e) is 0", a, e);
- }
- if (b + c == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(b) and {1}(c) is 0", b, c);
- }
- if (b + d == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(b) and {1}(d) is 0", b, d);
- }
- if (b + e == 0)
- {
- counter++;
- counter++;
- Console.WriteLine("The sum of {0}(b) and {1}(e) is 0", b, e);
- }
- if (c + d == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(c) and {1}(d) is 0", c, d);
- }
- if (c + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(c) and {1}(e) is 0", c, e);
- }
- if (d + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(d) and {1}(e) is 0", d, e);
- }
- //Checking every subset of three members
- if (a + b + c == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(b) and {2}(c) is 0", a, b, c);
- }
- if (a + b + d == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(b) and {2}(d) is 0", a, b, d);
- }
- if (a + b + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(b) and {2}(e) is 0", a, b, e);
- }
- if (a + c + d == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(c) and {2}(d) is 0", a, c, d);
- }
- if (a + c + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(c) and {2}(e) is 0", a, c, e);
- }
- if (a + d + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(d) and {2}(e) is 0", a, d, e);
- }
- if (b + c + d == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(b), {1}(c) and {2}(d) is 0", b, c, d);
- }
- if (b + c + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(b), {1}(c) and {2}(e) is 0", b, c, e);
- }
- if (b + d + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(b), {1}(d) and {2}(e) is 0", b, d, e);
- }
- if (c + d + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(c), {1}(d) and {2}(e) is 0", c, d, e);
- }
- //Checking for everysubset of four members
- if (a + b + c + d == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(b), {2}(c) and {3}(d) is 0", a, b, c, d);
- }
- if (a + b + c + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(b), {2}(c) and {3}(e) is 0", a, b, c, e);
- }
- if (a + b + d + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(b), {2}(d) and {3}(e) is 0", a, b, d, e);
- }
- if (a + c + d + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(a), {1}(c), {2}(d) and {3}(e) is 0", a, c, d, e);
- }
- if (b + c + d + e == 0)
- {
- counter++;
- Console.WriteLine("The sum of {0}(b), {1}(c), {2}(d) and {3}(e) is 0", b, c, d, e);
- }
- if (counter == 1)
- {
- Console.WriteLine("\nThere is 1 subset with sum equal to zero!");
- }
- else
- {
- Console.WriteLine("\nThere are {0} subsets with sum equal to zero!", counter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement