Advertisement
aspire12

8.CondensedArrayToNumber2.0

Feb 9th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _8.CondensedArrayToNumber1._1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //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}.
  11.  
  12.             int[] inputArrayInteger = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.             while (inputArrayInteger.Length  > 1)
  14.             {
  15.                 int[] condensedArray = new int[inputArrayInteger.Length - 1];
  16.  
  17.                 for (int j = 0; j < condensedArray.Length; j++)
  18.                 {
  19.                     condensedArray[j] = inputArrayInteger[j] + inputArrayInteger[j + 1];
  20.                 }
  21.                 inputArrayInteger = condensedArray;
  22.             }
  23.             Console.WriteLine(inputArrayInteger[0]);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement