Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CompareArrays
- {
- /* Да се напише програма, която чете два масива от конзолата и проверява дали са еднакви
- * Два масива са еднакви, когато имат еднаква дължина и стойностите на елементите в тях
- * съответно съвпадат. Второто условие можете да проверите с for цикъл.
- */
- class ArrayComparison
- {
- static void Main(string[] args)
- {
- Console.WriteLine("How many elements in the first array?");
- int firstArrayElmnts = int.Parse(Console.ReadLine());
- int[] arrayOne = new int[firstArrayElmnts];
- Console.WriteLine("How many elements in the second array?");
- int secondArrayElmnts = int.Parse(Console.ReadLine());
- int[] arrayTwo = new int[secondArrayElmnts];
- bool equal = false;
- int arrayOneValueTemp = 0;
- int arrayTwoValueTemp = 0;
- //check if first condition (equal lenght) is true
- if (firstArrayElmnts != secondArrayElmnts)
- {
- Console.WriteLine("It's {0} that the arrays are equal", equal);
- }
- else //if length differs, then compare element values
- {
- for (int i = 0; i < arrayOne.Length; i++)
- {
- Console.WriteLine("Enter value for the first array");
- arrayOne[i] = int.Parse(Console.ReadLine());
- arrayOneValueTemp = arrayOne[i];
- }
- for (int i = 0; i < arrayTwo.Length; i++)
- {
- Console.WriteLine("Enter value for the second array");
- arrayTwo[i] = int.Parse(Console.ReadLine());
- arrayTwoValueTemp = arrayTwo[i];
- }
- if (arrayOneValueTemp != arrayTwoValueTemp)
- {
- Console.WriteLine("The arrays are not equal!");
- return;
- }
- }
- Console.WriteLine("The arrays are equal!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement