Write a C# program that reads two arrays and checks whether they are equal.
Object:
Write a C# program that reads two arrays from the console and checks whether they are equal. C# Projects with Source Code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab_5a
{
class chkequal
{
public void chk()
{
int i, j,a,b;
Console.WriteLine(“How many value your enter in Arrays 1?”);
a = Convert.ToInt32(Console.ReadLine());
int[ ] arr1 = new int[a];
Console.WriteLine(“\nPlease Enter Arrays 1 Values. \n”);
for (i = 0; i < a; i++)
{
j = Convert.ToInt32(Console.ReadLine());
arr1[i] = j;
}
Console.WriteLine(“\nHow many value your enter in Arrays 2?”);
b = Convert.ToInt32(Console.ReadLine());
int[] arr2 = new int[b];
Console.WriteLine(“\nPlease Enter Arrays 2 Values. \n”);
for (i = 0; i < b; i++)
{
j = Convert.ToInt32(Console.ReadLine());
arr2[i] = j;
}
int a1 = arr1.Length;
int a2 = arr2.Length;
Console.WriteLine(“—————————————–“);
if (a1 == a2)
{
Console.WriteLine(“\nArrays are Equal.”);
}
else
Console.WriteLine(“\nArrays are not Equal.”);
}
}
class Program
{
static void Main(string[] args)
{
chkequal i = new chkequal();
i.chk();
Console.ReadKey();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lab_5a { class chkequal { public void chk() { int i, j,a,b; Console.WriteLine("How many value your enter in Arrays 1?"); a = Convert.ToInt32(Console.ReadLine()); int[] arr1 = new int[a]; Console.WriteLine("\nPlease Enter Arrays 1 Values. \n"); for (i = 0; i < a; i++) { j = Convert.ToInt32(Console.ReadLine()); arr1[i] = j; } Console.WriteLine("\nHow many value your enter in Arrays 2?"); b = Convert.ToInt32(Console.ReadLine()); int[] arr2 = new int[b]; Console.WriteLine("\nPlease Enter Arrays 2 Values. \n"); for (i = 0; i < b; i++) { j = Convert.ToInt32(Console.ReadLine()); arr2[i] = j; } int a1 = arr1.Length; int a2 = arr2.Length; Console.WriteLine("-----------------------------------------"); if (a1 == a2) { Console.WriteLine("\nArrays are Equal."); } else Console.WriteLine("\nArrays are not Equal."); } } class Program { static void Main(string[] args) { chkequal i = new chkequal(); i.chk(); Console.ReadKey(); } } }
Output:
Another C# Program: C# Program Calculating the Area of a Rectangle
Another C# Program: C# Program that Subtracts two user-defined numbers
Another C# Program: C# program to count vowels in a string
Pingback: C# Program Create an inheritance hierarchy that a bank might use to represent the customer's bank accounts.