Advertisement
YORDAN2347

EqualArrays

Jan 28th, 2021
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace EqualArrays
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr1 = Console.ReadLine()
  11.                 .Split()
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.             int[] arr2 = Console.ReadLine()
  15.                 .Split()
  16.                 .Select(int.Parse)
  17.                 .ToArray();
  18.  
  19.             int sum = 0;
  20.  
  21.             for (int i = 0; i < arr1.Length; i++)
  22.             {
  23.                 if (arr1[i] == arr2[i])
  24.                     sum += arr1[i];
  25.  
  26.                 else
  27.                 {
  28.                     Console.WriteLine($"Arrays are not identical. Found difference at {i} index");
  29.                     return;
  30.                 }
  31.             }
  32.             Console.WriteLine($"Arrays are identical. Sum: {sum}");
  33.         }
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement