Advertisement
dian_atanasov

Array

Dec 17th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. /*02. Write a program that reads two arrays from the console and compares them element by element.*/
  2. using System;
  3.  
  4. class ComparesElementsInArrays
  5. {
  6.     static void Main()
  7.     {
  8.         Console.Write("Enter the lenght of first array: ");
  9.         int sizeArrayOne = int.Parse(Console.ReadLine());
  10.         int[] arrayOne = new int[sizeArrayOne];
  11.  
  12.         Console.Write("Enter the lenght of the second array: ");
  13.         int sizeArrayTwo = int.Parse(Console.ReadLine());
  14.         int[] arrayTwo = new int[sizeArrayTwo];
  15.         int sizeArray = sizeArrayOne;
  16.  
  17.         bool isEqualSize = (sizeArrayOne == sizeArrayTwo);
  18.         if (!isEqualSize)
  19.         {
  20.             Console.WriteLine("The lenght of arrays are not equals.");
  21.         }
  22.         else
  23.         {
  24.             for (int index = 0; index < sizeArray; index++)
  25.             {
  26.                 Console.Write("Enter element for the first array [{0}]: ", index);
  27.                 arrayOne[index] = int.Parse(Console.ReadLine());
  28.                 Console.Write("Enter element for the second array [{0}]: ", index);
  29.                 arrayTwo[index] = int.Parse(Console.ReadLine());
  30.  
  31.                 if (arrayOne[index] == arrayTwo[index])
  32.                 {
  33.                     Console.WriteLine("The elements are equals");
  34.                     continue;
  35.                 }
  36.                 else
  37.                 {
  38.                     Console.WriteLine("The elements are not equals");
  39.                     Console.WriteLine("The element {0} is not equal to the element {1}", arrayOne[index], arrayTwo[index]);
  40.                     break;
  41.                 }
  42.                
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement