TheBulgarianWolf

Are-The-Arrays-Equal?

Dec 17th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace jaggedArrays
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter the length of the first array: ");
  14.             int n = int.Parse(Console.ReadLine());
  15.             int[] array1 = new int[n];
  16.             for(int i = 0;i < n; i++)
  17.             {
  18.                 Console.Write("Element {0} = ", i + 1);
  19.                 array1[i] = int.Parse(Console.ReadLine());
  20.             }
  21.             Console.WriteLine("Enter the length of the second array: ");
  22.             int k = int.Parse(Console.ReadLine());
  23.             int[] array2 = new int[k];
  24.             for (int i = 0; i < k; i++)
  25.             {
  26.                 Console.Write("Element {0} = ", i + 1);
  27.                 array2[i] = int.Parse(Console.ReadLine());
  28.             }
  29.  
  30.             bool isIt = true;
  31.             if (n == k)
  32.             {
  33.                
  34.                 for (int i = 0; i < k; i++)
  35.                 {
  36.                    
  37.                     if(array1[i] != array2[i])
  38.                     {
  39.                         isIt = false;
  40.                         break;
  41.                     }
  42.                    
  43.                 }
  44.             }
  45.             else
  46.             {
  47.                 Console.WriteLine("The arrays aren't equal!");
  48.             }
  49.  
  50.             if(isIt == false)
  51.             {
  52.                 Console.WriteLine("The arrays aren't equal!");
  53.             }
  54.             else
  55.             {
  56.                 Console.WriteLine("The arrays are equal.");
  57.             }
  58.             Console.ReadLine();
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment