Advertisement
hrimar

Arrays 3. Fold and Sum of Programming Fundamentals

Jun 11th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03FoldandSum
  6. {
  7.     class FoldAndSum
  8.     {
  9.         static void Main()
  10.         {
  11.             var nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.             var result = new int[nums.Length / 2];
  13.  
  14.             for (int i = 0; i < nums.Length / 4; i++)
  15.             {
  16.                 result[i] = (nums[nums.Length / 4 - 1 - i] + nums[i + nums.Length / 4]);
  17.             }
  18.             for (int i = 0; i < nums.Length / 4; i++)
  19.             {
  20.                 result[result.Length / 2 + i] = (nums[nums.Length - i - 1] + nums[(i + nums.Length / 2)]);
  21.             }
  22.  
  23.             Console.WriteLine(string.Join(" ", result));
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement