TheBulgarianWolf

Fold and Sum

Oct 19th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 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. using System.Threading;
  7.  
  8. namespace SoftuniExercisesWithVariables
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.  
  15.             Console.WriteLine("Enter your array here: ");
  16.             int[] array = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  17.             int[] array1 = new int[array.Length/2];
  18.             int[] array2 = new int[array.Length / 2];
  19.             int count2 = 0;
  20.             int count = 0;
  21.             for(int i = array.Length / 4-1; i >= 0; i--)
  22.             {
  23.                 array1[count] = array[i];
  24.                 count++;
  25.                 count2++;
  26.             }
  27.             int count1 = 0;
  28.             for(int k = array.Length / 4; k < array.Length/4+ array.Length / 2; k++)
  29.             {
  30.                
  31.                 array2[count1] = array[k];
  32.                 count1++;
  33.             }
  34.             for(int l = array.Length-1; l >= array.Length / 4 + array.Length / 2; l--)
  35.             {
  36.                 array1[count2] = array[l];
  37.                 count2++;
  38.             }
  39.  
  40.             foreach(int k in array1)
  41.             {
  42.                 Console.Write(k + " ");
  43.             }
  44.             Console.WriteLine();
  45.             foreach (int s in array2)
  46.             {
  47.                 Console.Write(s + " ");
  48.             }
  49.  
  50.             int[] summedArray = new int[array1.Length];
  51.             for(int j = 0; j < summedArray.Length; j++)
  52.             {
  53.                 summedArray[j] = array1[j] + array2[j];
  54.             }
  55.             Console.WriteLine();
  56.             foreach (int h in summedArray)
  57.             {
  58.                 Console.Write(h + " ");
  59.             }
  60.         }
  61.     }
  62. }
  63.  
Add Comment
Please, Sign In to add comment