Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write a program that reads two arrays from the console and compares them element by element.
- class Program
- {
- static void Main()
- {
- Console.Write("Enter the length of 1st array: ");
- int lengthOne = int.Parse(Console.ReadLine());
- string[] arrayOne = new string[lengthOne];
- for (int firstArray = 0; firstArray < lengthOne; firstArray++)
- {
- Console.Write("Enter array[{0}] = ", firstArray);
- arrayOne[firstArray] = Console.ReadLine();
- }
- Console.Write("Enter the length of 2nd array: ");
- int lengthTwo = int.Parse(Console.ReadLine());
- string[] arrayTwo = new string[lengthTwo];
- for (int secondArray = 0; secondArray < lengthTwo; secondArray++)
- {
- Console.Write("Enter array[{0}] = ", secondArray);
- arrayTwo[secondArray] = Console.ReadLine();
- }
- bool isEqual = true;
- //Start comparing
- if (arrayOne.Length == arrayTwo.Length)
- {
- for (int i = 0; i < arrayOne.Length; i++)
- {
- if (arrayOne[i] == arrayTwo[i])
- {
- isEqual = true;
- }
- else
- {
- isEqual = false;
- }
- }
- }
- else
- {
- isEqual = false;
- }
- Console.WriteLine("The two arrays are {0} !", isEqual ? "Equal" : "Different");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment