nadia_dr

Untitled

Nov 6th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2.  
  3. class CharArrays
  4. {
  5.     static void Main()
  6.     {
  7.         //Write a program that compares two char arrays lexicographically (letter by letter).
  8.  
  9.         Console.Write("Enter length for first array n = ");
  10.         int n = int.Parse(Console.ReadLine());
  11.         Console.Write("Enter length for second array m = ");
  12.         int m = int.Parse(Console.ReadLine());
  13.  
  14.         char[] firstArray = new char[n];
  15.         char[] secondArray = new char[m];
  16.  
  17.         for (int i = 0; i < n; i++)
  18.         {
  19.             Console.WriteLine("enter letter for first array: ");
  20.             firstArray[i] =char.Parse (Console.ReadLine());
  21.         }
  22.         for (int i = 0; i < m; i++)
  23.         {
  24.             Console.WriteLine("enter letter for second array: ");
  25.             secondArray[i] = char.Parse(Console.ReadLine());
  26.         }
  27.         bool Same = true;
  28.         if (n == m)
  29.         {
  30.             for (int i = 0; i < m; i++)
  31.             {
  32.                 if (firstArray[i] != secondArray[i])
  33.                 {
  34.                     Same = false;
  35.  
  36.                 }
  37.             }
  38.  
  39.         }
  40.         else if (n != m)
  41.         {
  42.             Same = false;
  43.  
  44.         }
  45.         Console.WriteLine(Same);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment