Advertisement
Booster

Sum of subset of 5 numbers is 0 if-else

Jul 26th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. using System;
  2.  
  3. class SubsetOfNumbersIs0
  4. {
  5. static void Main()
  6. { //Find if sum of some numbers is 0
  7. int a = 2;
  8. int b = 3;
  9. int c = 5;
  10. int d = -9;
  11. int e = 6;
  12. //All sum combinations if-else construction
  13. if (a + b != 0)
  14. {
  15. if (a + b + c != 0)
  16. {
  17. if (a + b + c + d != 0)
  18. {
  19. if (a + b + c + d + e == 0)
  20. {
  21. Console.WriteLine(
  22. "{0} + {1} + {2} + {3} + {4} = 0", a, b, c, d, e);
  23. }
  24. }
  25. else
  26. {
  27. Console.WriteLine("{0} + {1} + {2} + {3} = 0", a, b, c, d);
  28. }
  29. }
  30. else
  31. {
  32. Console.WriteLine("{0} + {1} + {2} = 0", a, b, c);
  33. }
  34. if (a + b + d != 0)
  35. {
  36. if (a + b + d + e == 0)
  37. {
  38. Console.WriteLine("{0} + {1} + {2} + {3}= 0", a, b, d, e);
  39. }
  40. }
  41. else
  42. {
  43. Console.WriteLine("{0} + {1} + {2} = 0", a, b, d);
  44. }
  45. if (a + b + e == 0)
  46. {
  47. Console.WriteLine("{0} + {1} + {2} = 0", a, b, e);
  48. }
  49. }
  50. else
  51. {
  52. Console.WriteLine("{0} + {1} = 0", a, b);
  53. }
  54. if (a + c != 0)
  55. {
  56. if (a + c + d != 0)
  57. {
  58. if (a + c + e ==0)
  59. {
  60. Console.WriteLine("{0} + {1} + {2} = 0", a, c, e);
  61. }
  62. if (a + c + d + e == 0)
  63. {
  64. Console.WriteLine("{0} + {1} + {2} + {3} = 0", a, c, d, e);
  65. }
  66. }
  67. else
  68. {
  69. Console.WriteLine("{0} + {1} + {2} = 0", a, c, d);
  70. }
  71. }
  72. else
  73. {
  74. Console.WriteLine("{0} + {1} = 0", a, c);
  75. }
  76. if (a + d != 0)
  77. {
  78. if (a + d + e != 0)
  79. {
  80. }
  81. else
  82. {
  83. Console.WriteLine("{0} + {1} + {2} = 0", a, d, e);
  84. }
  85. }
  86. else
  87. {
  88. Console.WriteLine("{0} + {1} = 0", a, d);
  89. }
  90. if (a + e != 0)
  91. {
  92.  
  93. }
  94. else
  95. {
  96. Console.WriteLine("{0} + {1} = 0", a, e);
  97. }
  98. if (b + c != 0)
  99. {
  100. if (b + c + d != 0)
  101. {
  102. if (b + c + e == 0)
  103. {
  104. Console.WriteLine("{0} + {1} + {2} = 0", b, c, e);
  105. }
  106. if (b + c + d + e == 0)
  107. {
  108. Console.WriteLine("{0} + {1} + {2} + {3} = 0", b, c, d, e);
  109. }
  110. }
  111. else
  112. {
  113. Console.WriteLine("{0} + {1} + {2} = 0", b, c, d);
  114. }
  115. }
  116. else
  117. {
  118. Console.WriteLine("{0} + {1} = 0", b, c);
  119. }
  120. if (c + d != 0)
  121. {
  122. if (c + d + e == 0)
  123. {
  124. Console.WriteLine("{0} + {1} + {2} = 0", c, d, e);
  125. }
  126. }
  127. else
  128. {
  129. Console.WriteLine("{0} + {1} = 0", c, d);
  130. }
  131. if (d + e == 0)
  132. {
  133. Console.WriteLine("{0} + {1} = 0", d, e);
  134. }
  135. if (b + d != 0)
  136. {
  137. if (b + d + e == 0)
  138. {
  139. Console.WriteLine("{0} + {1} + {2} = 0", b, d, e);
  140. }
  141. }
  142. else
  143. {
  144. Console.WriteLine("{0} + {1} = 0", b, d);
  145. }
  146. if (b + e == 0)
  147. {
  148. Console.WriteLine("{0} + {1} = 0", b, e);
  149. }
  150. if (c + d == 0)
  151. {
  152. Console.WriteLine("{0} + {1} = 0", c, d);
  153. }
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement