emodev

Equal Arrays

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