kirililchev3

Sum Array

Jun 3rd, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. namespace Sum_Arrays
  2. {
  3.     using System;
  4.  
  5.     public class Sum_Arrays
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string[] row1 = Console.ReadLine().Split();
  10.             string[] row2 = Console.ReadLine().Split();
  11.  
  12.             int[] arr1 = new int[row1.Length];
  13.             for (int i = 0; i < arr1.Length; i++)
  14.             {
  15.                 arr1[i] = int.Parse(row1[i]);
  16.             }
  17.  
  18.             int[] arr2 = new int[row2.Length];
  19.             for (int i = 0; i < arr2.Length; i++)
  20.             {
  21.                 arr2[i] = int.Parse(row2[i]);
  22.             }
  23.  
  24.             for (int i = 0, j = 0, k = 0; k < Math.Max(arr1.Length, arr2.Length); i++, j++, k++)
  25.             {
  26.                 if (i == arr1.Length)
  27.                 {
  28.                     i = 0;
  29.                 }
  30.  
  31.                 if (j == arr2.Length)
  32.                 {
  33.                     j = 0;
  34.                 }
  35.  
  36.                 Console.Write("{0} ", arr1[i] + arr2[j]);
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment