Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CompareTwoArrays
- {
- static void Main()
- {
- // Write a program that reads two arrays from the console and compares them element by element.
- Console.Title = "Compare two arrays for equality";
- Console.WriteLine("Array 1 - Enter values on one line separated by space: ");
- string[] arrayOne = Console.ReadLine().Split();
- Console.WriteLine("Array 2 - Enter values on one line separated by space: ");
- string[] arrayTwo = Console.ReadLine().Split();
- if (arrayOne.Length != arrayTwo.Length)
- {
- Console.WriteLine("Your arrays are with different sizes, so they can not be equal!");
- }
- else
- {
- bool[] equalsArray = new bool[arrayOne.Length];
- Console.WriteLine("{0,10}{1,10}{2,10}", "Array 1", "Array 2", "Equal?");
- Console.WriteLine(new string('-', 30));
- for (int i = 0; i < arrayOne.Length; i++)
- {
- if (arrayOne[i] == arrayTwo[i])
- {
- equalsArray[i] = true;
- }
- Console.WriteLine("{0,8}{1,10}{2,11}", arrayOne[i], arrayTwo[i], equalsArray[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement