Advertisement
tanya_zheleva

Sum

Jan 30th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ExamPreparation
  5. {
  6.     class Startup
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] firstArray = Console.ReadLine()
  11.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.             int[] secondArray = Console.ReadLine()
  15.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  16.                 .Select(int.Parse)
  17.                 .ToArray();
  18.  
  19.             int length = Math.Max(firstArray.Length, secondArray.Length);
  20.             int[] summed = new int[length];
  21.  
  22.             for (int i = 0; i < summed.Length; i++)
  23.             {
  24.                 summed[i] = firstArray[i % firstArray.Length] + secondArray[i % secondArray.Length];
  25.             }
  26.  
  27.             Console.WriteLine(string.Join(" ", summed));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement