Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class SubsetOfNumbersIs0
- {
- static void Main()
- { //Find if sum of some numbers is 0
- int a = 2;
- int b = 3;
- int c = 5;
- int d = -9;
- int e = 6;
- //All sum combinations if-else construction
- if (a + b != 0)
- {
- if (a + b + c != 0)
- {
- if (a + b + c + d != 0)
- {
- if (a + b + c + d + e == 0)
- {
- Console.WriteLine(
- "{0} + {1} + {2} + {3} + {4} = 0", a, b, c, d, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} + {2} + {3} = 0", a, b, c, d);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} + {2} = 0", a, b, c);
- }
- if (a + b + d != 0)
- {
- if (a + b + d + e == 0)
- {
- Console.WriteLine("{0} + {1} + {2} + {3}= 0", a, b, d, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} + {2} = 0", a, b, d);
- }
- if (a + b + e == 0)
- {
- Console.WriteLine("{0} + {1} + {2} = 0", a, b, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} = 0", a, b);
- }
- if (a + c != 0)
- {
- if (a + c + d != 0)
- {
- if (a + c + e ==0)
- {
- Console.WriteLine("{0} + {1} + {2} = 0", a, c, e);
- }
- if (a + c + d + e == 0)
- {
- Console.WriteLine("{0} + {1} + {2} + {3} = 0", a, c, d, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} + {2} = 0", a, c, d);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} = 0", a, c);
- }
- if (a + d != 0)
- {
- if (a + d + e != 0)
- {
- }
- else
- {
- Console.WriteLine("{0} + {1} + {2} = 0", a, d, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} = 0", a, d);
- }
- if (a + e != 0)
- {
- }
- else
- {
- Console.WriteLine("{0} + {1} = 0", a, e);
- }
- if (b + c != 0)
- {
- if (b + c + d != 0)
- {
- if (b + c + e == 0)
- {
- Console.WriteLine("{0} + {1} + {2} = 0", b, c, e);
- }
- if (b + c + d + e == 0)
- {
- Console.WriteLine("{0} + {1} + {2} + {3} = 0", b, c, d, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} + {2} = 0", b, c, d);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} = 0", b, c);
- }
- if (c + d != 0)
- {
- if (c + d + e == 0)
- {
- Console.WriteLine("{0} + {1} + {2} = 0", c, d, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} = 0", c, d);
- }
- if (d + e == 0)
- {
- Console.WriteLine("{0} + {1} = 0", d, e);
- }
- if (b + d != 0)
- {
- if (b + d + e == 0)
- {
- Console.WriteLine("{0} + {1} + {2} = 0", b, d, e);
- }
- }
- else
- {
- Console.WriteLine("{0} + {1} = 0", b, d);
- }
- if (b + e == 0)
- {
- Console.WriteLine("{0} + {1} = 0", b, e);
- }
- if (c + d == 0)
- {
- Console.WriteLine("{0} + {1} = 0", c, d);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement