Advertisement
CuST0M1z3

SubsetSumEqualToZero

May 14th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2.  
  3. class SubsetSumEqualToZero
  4. {
  5.     static void Main()
  6.     {
  7.         int[] arr = new int[5];
  8.         int sum = 0;
  9.         int count = 0;
  10.  
  11.  
  12.         for (int i = 0; i < arr.Length; i++)
  13.         {
  14.             arr[i] = int.Parse(Console.ReadLine());
  15.         }
  16.         for (int j = 0; j < 5; j++)
  17.         {
  18.             sum = 0;
  19.             for (int k = j; k < 5; k++)
  20.             {
  21.                 sum += arr[k];
  22.  
  23.                 if (sum == 0)
  24.                 {
  25.                    
  26.                     count++;
  27.                    
  28.                 }
  29.             }
  30.         }
  31.  
  32.         Console.WriteLine("The subset sum which is equal to zero are:" + count);
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement