VelizarAvramov

07. Sum Arrays

Nov 25th, 2018
128
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 _07._Sum_Arrays
  5. {
  6.     class SumArrays
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] firstArr = Console.ReadLine()
  11.                 .Split().Select(int.Parse).ToArray();
  12.  
  13.             int[] secondArr = Console.ReadLine()
  14.                 .Split().Select(int.Parse).ToArray();
  15.  
  16.             int[] sumArr = new int[Math.Max(firstArr.Length, secondArr.Length)];
  17.  
  18.             for (int i = 0; i < sumArr.Length; i++)
  19.             {
  20.                 sumArr[i] = firstArr[i % firstArr.Length] + secondArr[i % secondArr.Length];
  21.             }
  22.             foreach (var sum in sumArr)
  23.             {
  24.                 Console.Write(string.Join(" ", $"{sum} "));
  25.             }
  26.             Console.WriteLine();
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment