Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = { 4, 3, 1, 4, 2, 5, 8 };
- int s = 15;
- int sum = array[0];
- int start = 0, count = 1;
- for (int i = 1; i < array.Length; i++)
- {
- if (sum + array[i] == s)
- {
- count++;
- for (int j = start; j < start + count; j++)
- {
- Console.Write("{0} ",array[j]);
- }
- Console.WriteLine();
- }
- else if (sum + array[i] < s)
- {
- sum = array[i] + sum;
- count++;
- }
- else if (sum + array[i] > s)
- {
- sum = array[i - count + 1];
- start = i - count + 1;
- i = start;
- count = 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment