Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*
- * 2. Write a program that reads two arrays from the console and compares them element by element.
- */
- class TwoArraysEqual
- {
- static void Main()
- {
- int n;
- int m;
- bool equal = true;
- Console.Write("Number of the first array elements: ");
- string strN = Console.ReadLine();
- Console.Write("Number of the second array elements: ");
- string strM = Console.ReadLine();
- if (!int.TryParse(strN, out n) || !int.TryParse(strM, out m))
- {
- Console.WriteLine("Invalid numbers!");
- }
- else
- {
- if (n != m)
- {
- equal = false;
- }
- else
- {
- int[] firstArr = new int[n];
- int[] secondArr = new int[m];
- for (int i = 0; i < firstArr.Length; i++)
- {
- Console.Write("Please enter a first array elements: ");
- firstArr[i] = int.Parse(Console.ReadLine());
- }
- for (int j = 0; j < secondArr.Length; j++)
- {
- Console.Write("Please enter a second array elements: ");
- secondArr[j] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < firstArr.Length; i++)
- {
- if (firstArr[i] != secondArr[i])
- {
- equal = false;
- }
- }
- }
- Console.WriteLine("Arrays are equal? - {0}", equal);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement