TheBulgarianWolf

Condensed array

Oct 12th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Linq;
  5. using System.Numerics;
  6.  
  7. namespace SoftuniExercisesWithVariables
  8. {
  9.     class Program
  10.     {
  11.        
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             Console.WriteLine("Enter the numbers in your array:  ");
  16.             int[] array1 = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  17.             int length = array1.Length;
  18.             int[] condensed = new int[length-1];
  19.             while(length > 1)
  20.             {
  21.                 condensed = new int[length-1];
  22.                 for(int i = 0; i < condensed.Length; i++)
  23.                 {
  24.                     condensed[i] = array1[i] + array1[i + 1];
  25.                 }
  26.                 for(int m = 0; m < condensed.Length; m++)
  27.                 {
  28.                     array1[m] = condensed[m];
  29.                 }
  30.                 length--;
  31.             }
  32.             Console.WriteLine(condensed[0]);
  33.         }
  34.     }
  35. }
  36.  
Add Comment
Please, Sign In to add comment