Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*02. Write a program that reads two arrays from the console and compares them element by element.*/
- using System;
- class ComparesElementsInArrays
- {
- static void Main()
- {
- Console.Write("Enter the lenght of first array: ");
- int sizeArrayOne = int.Parse(Console.ReadLine());
- int[] arrayOne = new int[sizeArrayOne];
- Console.Write("Enter the lenght of the second array: ");
- int sizeArrayTwo = int.Parse(Console.ReadLine());
- int[] arrayTwo = new int[sizeArrayTwo];
- int sizeArray = sizeArrayOne;
- bool isEqualSize = (sizeArrayOne == sizeArrayTwo);
- if (!isEqualSize)
- {
- Console.WriteLine("The lenght of arrays are not equals.");
- }
- else
- {
- for (int index = 0; index < sizeArray; index++)
- {
- Console.Write("Enter element for the first array [{0}]: ", index);
- arrayOne[index] = int.Parse(Console.ReadLine());
- Console.Write("Enter element for the second array [{0}]: ", index);
- arrayTwo[index] = int.Parse(Console.ReadLine());
- if (arrayOne[index] == arrayTwo[index])
- {
- Console.WriteLine("The elements are equals");
- continue;
- }
- else
- {
- Console.WriteLine("The elements are not equals");
- Console.WriteLine("The element {0} is not equal to the element {1}", arrayOne[index], arrayTwo[index]);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement