Advertisement
KeepCoding

ArrayLabProblem8CondenseArrayToNumber

Feb 6th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace FixCode
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.  
  11.             int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.             if (arr.Length == 1)
  13.             {
  14.                 Console.WriteLine(arr[0]);
  15.             }
  16.             else
  17.             {
  18.                 int lastIndex = arr.Length - 1;
  19.                 while (lastIndex != 0)
  20.                 {
  21.                     for (int i = 0; i < lastIndex; i++)
  22.                     {
  23.                         arr[i] += arr[i + 1];
  24.                     }
  25.                     arr[lastIndex] = 0;
  26.                     lastIndex--;
  27.                 }
  28.                 Console.WriteLine(arr[0]);
  29.  
  30.  
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement