Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // 2. Write a program that reads two arrays from the console and compares them element by element.
- class ComparingElementsInArrays
- {
- static void Main()
- {
- Console.Write("Type the number of integers in the arrays here: ");
- // the length of the arrays
- int n = int.Parse(Console.ReadLine());
- // allocating the arrays
- int[] firstArr = new int[n];
- int[] secondArr = new int[n];
- Console.WriteLine("Type {0} numbers in the first array: ", n);
- for (int i = 0; i < firstArr.Length; i++) // firstArr.Length = secondArr.Length = n
- {
- firstArr[i] = int.Parse(Console.ReadLine());
- }
- Console.WriteLine("Type {0} numbers in the second array: ", n);
- for (int i = 0; i < secondArr.Length; i++)
- {
- secondArr[i] = int.Parse(Console.ReadLine());
- }
- // checking if the elements in the arrays with equal index have equal values too
- for (int i = 0; i < n ; i++)
- {
- if (firstArr[i] != secondArr[i])
- {
- Console.WriteLine("{0} is not equal to {1} !", firstArr[i], secondArr[i]);
- }
- else
- {
- Console.WriteLine("{0} is equal to {1} !!! ", firstArr[i], secondArr[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement