Advertisement
stoianpp

Arrays2

Dec 11th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. class Comparisson2Arrays
  3. {
  4.     static void Main()
  5.     {
  6.         Console.Write("Enter the array length: ");
  7.         int length = int.Parse(Console.ReadLine());
  8.         int[] array1 = new int[length];
  9.         int[] array2 = new int[length];
  10.        
  11.         for (int i = 0; i < length; i++)
  12.         {
  13.             Console.Write("Enter the Array1 Element[{0}] value: ",i+1);
  14.             array1[i] = int.Parse(Console.ReadLine());
  15.             Console.Write("Enter the Array2 Element[{0}] value: ", i+1);
  16.             array2[i] = int.Parse(Console.ReadLine());
  17.             Console.WriteLine();
  18.         }
  19.        
  20.         for (int i = 0; i < length; i++)
  21.         {
  22.             int compare = array1[i].CompareTo(array2[i]);
  23.             string result = "";
  24.             switch (compare)
  25.             {
  26.                 case 1: result = "The element of the first array is bigger"; break;
  27.                 case 0: result = "The elements of the two arrays are equal"; break;
  28.                 case -1: result = "The element of the second array is bigger"; break;
  29.             }
  30.             Console.WriteLine("Element[{0}]: {1}", i+1, result);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement