Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class IsSomeSumOf5IntNumsEqualToZero
- {
- static void Main()
- {
- //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.
- Console.Write("Enter the first integer number: ");
- int num1 = int.Parse(Console.ReadLine());
- Console.Write("Enter the second integer number: ");
- int num2 = int.Parse(Console.ReadLine());
- Console.Write("Enter the third integer number: ");
- int num3 = int.Parse(Console.ReadLine());
- Console.Write("Enter the fourth integer number: ");
- int num4 = int.Parse(Console.ReadLine());
- Console.Write("Enter the fifth integer number: ");
- int num5 = int.Parse(Console.ReadLine());
- int sum = 0;
- for (byte combination0 = 0; combination0 < 2; combination0++)
- {
- for (byte combination1 = 0; combination1 < 2; combination1++)
- {
- for (byte combination2 = 0; combination2 < 2; combination2++)
- {
- for (byte combination3 = 0; combination3 < 2; combination3++)
- {
- for (byte combination4 = 0; combination4 < 2; combination4++)
- {
- sum = 0;
- if ((combination0 != 0) || (combination1 != 0) || (combination2 != 0) || (combination3 != 0) || (combination4 != 0))
- {
- sum = combination0 * num1 + combination1 * num2 + combination2 * num3 + combination3 * num4 + combination4 * num5;
- if (sum == 0)
- {
- Console.WriteLine("There is at least one subset Sum = 0!");
- return;
- }
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement