Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace CondenseArrayToNumber
- {
- 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();
- for (int i = 0; i < inputArrayInteger.Length - 1; i++)
- {
- for (int j = 0; j < inputArrayInteger.Length - 1; j++)
- {
- inputArrayInteger[j] = inputArrayInteger[j] + inputArrayInteger[j + 1];
- }
- }
- Console.WriteLine(inputArrayInteger[0]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement