Venciity

[C#] BOOK Arrays - 2 Задача

Jan 6th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. /* Write a program that reads
  2.  * two arrays from the console
  3.  * and compares them element by element.
  4.  */
  5.  
  6. using System;
  7.  
  8. class TwoArrayCompare
  9. {
  10.     static void Main()
  11.     {
  12.         Console.Write("Enter the array length: ");
  13.         int n = int.Parse(Console.ReadLine());
  14.         int[] firstArray = new int[n];
  15.         int[] secondArray = new int[n];
  16.         for (int i = 0; i < firstArray.Length; i++)
  17.         {
  18.             Console.Write("Enter element {0} from the first array: ",i+1);
  19.             firstArray[i] = int.Parse(Console.ReadLine());
  20.         }
  21.         Console.WriteLine();
  22.         for (int i = 0; i < firstArray.Length; i++)
  23.         {
  24.             Console.Write("Enter element {0} from the second array: ",i+1);
  25.             secondArray[i] = int.Parse(Console.ReadLine());
  26.         }
  27.  
  28.         bool areEqual = true;
  29.         for (int i = 0; i < firstArray.Length; i++)
  30.         {
  31.             if (firstArray[i] != secondArray[i])
  32.             {
  33.                 areEqual = false;
  34.                 break;
  35.             }
  36.         }
  37.         Console.WriteLine();
  38.         Console.WriteLine("arrays are equal ? - {0}", areEqual);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment