Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _8.CondensedArrayToNumber1._1
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Write a program to read an array of integers and condense them by summing adjacent couples of elements until a single integer is obtained. For example, if we have 3 elements {2, 10, 3}, we sum the first two and the second two elements and obtain {2+10, 10+3} = {12, 13}, then we sum again all adjacent elements and obtain {12+13} = {25}.
- int[] inputArrayInteger = Console.ReadLine().Split().Select(int.Parse).ToArray();
- while (inputArrayInteger.Length > 1)
- {
- int[] condensedArray = new int[inputArrayInteger.Length - 1];
- for (int j = 0; j < condensedArray.Length; j++)
- {
- condensedArray[j] = inputArrayInteger[j] + inputArrayInteger[j + 1];
- }
- inputArrayInteger = condensedArray;
- }
- Console.WriteLine(inputArrayInteger[0]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement