Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We are given 5 integer numbers. Write a program that checks if the sum of some subset of them is 0. Example: 3, -2, 1, 1, 8 1+1-2=0.
- using System;
- class Program
- {
- static void Main()
- {
- Console.WriteLine("Write 5 integer numbers:\n");
- Console.Write("First one: ");
- int first = int.Parse(Console.ReadLine());
- Console.Write("Second one: ");
- int second = int.Parse(Console.ReadLine());
- Console.Write("Third one: ");
- int third = int.Parse(Console.ReadLine());
- Console.Write("Fourth one: ");
- int fourth = int.Parse(Console.ReadLine());
- Console.Write("Fifth one: ");
- int fifth = int.Parse(Console.ReadLine());
- bool check = false;
- // We have 26 options between 5 numbers
- if (first + second == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", first, second);
- check = true;
- }
- if (first + third == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", first, third);
- check = true;
- }
- if (first + fourth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", first, fourth);
- check = true;
- }
- if (first + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", first, fifth);
- check = true;
- }
- if (second + third == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", second, third);
- check = true;
- }
- if (second + fourth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", second, fourth);
- check = true;
- }
- if (second + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", second, fifth);
- check = true;
- }
- if (third + fourth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", third, fourth);
- check = true;
- }
- if (third + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", third, fifth);
- check = true;
- }
- if (fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} is: 0", fourth, fifth);
- check = true;
- }
- if (first + second + third == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", first, second, third);
- check = true;
- }
- if (second + third + fourth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", second, third, fourth);
- check = true;
- }
- if (third + fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", third, fourth, fifth);
- check = true;
- }
- if (first + second + fourth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", first, second, fourth);
- check = true;
- }
- if (first + second + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", first, second, fifth);
- check = true;
- }
- if (second + third + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", second, third, fifth);
- check = true;
- }
- if (first + fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", first, fourth, fifth);
- check = true;
- }
- if (second + fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", second, fourth, fifth);
- check = true;
- }
- if (first + third + fourth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", first, second, fourth);
- check = true;
- }
- if (third + fourth + first == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} is: 0", third, fourth, first);
- check = true;
- }
- if (first + second + third + fourth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} {3} is: 0", first, second, third);
- check = true;
- }
- if (second + third + fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} {3} is: 0", second, third, fourth);
- check = true;
- }
- if (first + second + fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} {3} is: 0", first, second, fourth);
- check = true;
- }
- if (first + second + third + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} {3} is: 0", first, second, third, fifth);
- check = true;
- }
- if (first + third + fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} {3} is: 0", first, third, fourth, fifth);
- check = true;
- }
- if (first + second + third + fourth + fifth == 0)
- {
- Console.WriteLine("The sum of this subset {0} {1} {2} {3} {4} is: 0", first, second, third, fourth, fifth);
- check = true;
- }
- if (check == false)
- {
- Console.WriteLine("There is no subset Equal 0!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement