nikolayneykov

Untitled

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