vonko1988

c#SubsetOfFiveNumbers

Mar 16th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.05 KB | None | 0 0
  1. using System;
  2.  
  3. class SubsetsWIthSum0
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Write your subset of five integers: ");
  8.         int a = int.Parse(Console.ReadLine());
  9.         int b = int.Parse(Console.ReadLine());
  10.         int c = int.Parse(Console.ReadLine());
  11.         int d = int.Parse(Console.ReadLine());
  12.         int e = int.Parse(Console.ReadLine());
  13.  
  14.         if (a + b == 0)
  15.         {
  16.             Console.WriteLine("The sum of {0} and {1} is zero!", a,b);
  17.         }
  18.         else if (a + b + c == 0)
  19.         {
  20.             Console.WriteLine("The sum of {0}, {1} and {2} is zero!",a,b,c);
  21.         }
  22.         else if (a + b + c + d == 0)
  23.         {
  24.             Console.WriteLine("The sum of {0}, {1}, {2} and {3} is zero!",a,b,c,d);
  25.         }
  26.         else if (a + b + c + d + e == 0)
  27.         {
  28.             Console.WriteLine("The sum of {0}, {1}, {2}, {3} and {4} is zero!",a,b,c,d,e);
  29.         }
  30.         else if (a + c == 0)
  31.         {
  32.             Console.WriteLine("The sum of {0} and {1} is zero!", a,c);
  33.         }
  34.         else if (a + c + d == 0)
  35.         {
  36.             Console.WriteLine("The sum of {0}, {1} and {2} is zero!",a,c,d);
  37.         }
  38.         else if (a + c + d + e == 0)
  39.         {
  40.             Console.WriteLine("The sum of {0}, {1}, {2} and {3} is zero!",a,c,d,e);
  41.         }
  42.         else if (a + d == 0)
  43.         {
  44.             Console.WriteLine("The sum of {0} and {1} is zero!", a, d);
  45.         }
  46.         else if (a + d + e == 0)
  47.         {
  48.             Console.WriteLine("The sum of {0},{1} and {2} is zero!",a,d,e);
  49.         }
  50.         else if (a + e == 0)
  51.         {
  52.             Console.WriteLine("The sum of {0} and {1} is zero!", a,e);
  53.         }
  54.         else if (b + c == 0)
  55.         {
  56.             Console.WriteLine("The sum of {0} and {1} is zero!",b,c);
  57.         }
  58.         else if (b + c + d == 0)
  59.         {
  60.             Console.WriteLine("The sum of {0}, {1} and {2} is zero!",b,c,d);
  61.         }
  62.         else if (b + c + d + e == 0)
  63.         {
  64.             Console.WriteLine("The sum of {0}, {1}, {2} and {3} is zero!",b,c,d,e);
  65.         }
  66.         else if (b + d == 0)
  67.         {
  68.             Console.WriteLine("The sum of {0} and {1} is zero!",b,d);
  69.         }
  70.         else if (b + d + e == 0)
  71.         {
  72.             Console.WriteLine("The sum of {0}, {1} and {2} is zero!",b,d,e);
  73.         }
  74.         else if (b + e == 0)
  75.         {
  76.             Console.WriteLine("The sum of {0} and {1} is zero!", b,e);
  77.         }
  78.         else if (c + d == 0)
  79.         {
  80.             Console.WriteLine("The sum of {0} and {1} is zero!",c,d);
  81.         }
  82.         else if (c + d + e == 0)
  83.         {
  84.             Console.WriteLine("The sum of {0}, {1} and {2} is zero!",c,d,e);
  85.         }
  86.         else if (c + e == 0)
  87.         {
  88.             Console.WriteLine("The sum of {0} and {1} is zero!",c,e);
  89.         }
  90.         else if (d + e == 0)
  91.         {
  92.             Console.WriteLine("The sum of {0} and {1} is zero!", d,e);
  93.         }
  94.  
  95.         else
  96.         {
  97.             Console.WriteLine("There are no subsets with sum 0!");
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment