Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleTesting2
- {
- class ConsoleTesting2
- {
- static void Main()
- {
- Console.Write("Enter array length: ");
- int n = int.Parse(Console.ReadLine());
- Console.Write("Enter sum to be checked: ");
- int s = int.Parse(Console.ReadLine());
- var ints = new int[n];
- var collectedSeqs = new List<string>();
- for (int i = 0; i < n; i++)
- {
- Console.Write("Index \"{0}\": ", i);
- ints[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < ints.Length; i++)
- {
- var templist = new List<int>();
- templist.Add(ints[i]);
- for (int k = i+1; k < ints.Length; k++)
- {
- templist.Add(ints[k]);
- if (templist.Sum() == s)
- {
- string temp = string.Join(",", templist);
- collectedSeqs.Add(temp);
- }
- }
- }
- Console.WriteLine(new string('=', 25));
- Console.Write("Sequences with sum {0}:\n", s);
- foreach (var cl in collectedSeqs)
- {
- Console.WriteLine(cl);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment