Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Нека е дадена редица от цели числа.
- - при зададено от потребителя S, отпечатайте подредиците, сумата на елементите на които е равна на S
- Например: { 4, 3, 1, 4, 2, 5, 8 }, S=11 -> { 4, 2, 5 } */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _06B_TheSumOfANumberOfElements
- {
- class TheSumOfANumberOfElements
- {
- static void Main()
- {
- Console.Write("Numbers of array = ");
- int n = Int32.Parse(Console.ReadLine());
- int[] array = new int[n];
- for (int i = 0; i < n; i++)
- {
- Console.Write("Element {0} = ", i + 1);
- array[i] = Int32.Parse(Console.ReadLine());
- }
- int arrayLen = array.Length;
- Console.Write("Sum = ");
- int s = Int32.Parse(Console.ReadLine());
- for (int i = 0; i < arrayLen; i++)
- {
- int sum = 0;
- for (int j = i; j < arrayLen; j++)
- {
- sum += array[j];
- if (s == sum)
- {
- for (int k = i; k <= j; k++)
- {
- Console.Write(array[k] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment