Advertisement
Martichka

Arrays/ Task 8 - Sequence of max sum

Jan 12th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System;
  2. class SequenceMaxSum
  3. {
  4.     static void Main()
  5.     {
  6.         int[] array = { 2, 3, -6, -1, 2, -1, 6, 4, -8, 8 };
  7.         int localSum = 0;
  8.         int biggestSum = 0;
  9.         for (int index = 0; index < array.Length; index++)
  10.         {
  11.             localSum += array[index];
  12.  
  13.             if (localSum > biggestSum)
  14.             {
  15.                 biggestSum = localSum;
  16.             }
  17.             if (localSum == 0)
  18.             {
  19.                 localSum += array[index];
  20.             }
  21.         }
  22.         Console.WriteLine(biggestSum);
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement