Advertisement
aspire12

8.CondenseArrayToNumber

Feb 8th, 2020
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace CondenseArrayToNumber
  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.  
  13.             int[] inputArrayInteger = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.             for (int i = 0; i < inputArrayInteger.Length - 1; i++)
  15.             {
  16.                 for (int j = 0; j < inputArrayInteger.Length - 1; j++)
  17.                 {
  18.                     inputArrayInteger[j] = inputArrayInteger[j] + inputArrayInteger[j + 1];
  19.                 }
  20.             }
  21.             Console.WriteLine(inputArrayInteger[0]);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement