Qrist

Condense Array to Number

Apr 7th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace GitHub
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr1 = new int[] { 5,1,4,1,2 };
  11.             int[] arr2 = new int[arr1.Length - 1];
  12.             if (arr1.Length == 1)
  13.             {
  14.                 Console.WriteLine(arr1[0]);
  15.                 return;
  16.             }
  17.             for (int first = 0; first < arr1.Length; first++)
  18.             {
  19.                 Console.Write(arr1[first] + " ");
  20.                 for (int second = 0; second < arr2.Length - first; second++)
  21.                 {
  22.                     arr2[second] = arr1[second] + arr1[second + 1];
  23.  
  24.                 }
  25.                 arr1 = arr2;
  26.             }
  27.             Console.WriteLine("\nSum= " + arr1[0]);
  28.  
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment