Advertisement
dilyanyordanov

c# sum of arrays

Jun 1st, 2016
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem8_SumArray
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var arr1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             var arr2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); ;
  15.             var n = Math.Max(arr1.Length, arr2.Length);
  16.             var sumArr = new int[n];
  17.  
  18.             for (int i = 0; i < n; i++)
  19.                 sumArr[i] =
  20.                   arr1[i % arr1.Length] +
  21.                   arr2[i % arr2.Length];
  22.             Console.WriteLine(string.Join(" ", sumArr));
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement