Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace EqualArrElementsIntoNewArr
- {
- class EqualArrElementsIntoNewArr
- {
- static void Main()
- {
- Console.WriteLine("Input length of first array.");
- int n = int.Parse(Console.ReadLine());
- Console.WriteLine("Input length of second array.");
- int m = int.Parse(Console.ReadLine());
- int[] firstArr = new int[n];
- int[] secondArr = new int[m];
- for (int i = 0; i < n; i++)
- {
- Console.WriteLine("First array, Element {0}", (i+1));
- firstArr[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < m; i++)
- {
- Console.WriteLine("Second array, Element {0}", (i+1));
- secondArr[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < n; i++)
- { Console.Write(firstArr[i] + " "); }
- Console.WriteLine();
- for (int i = 0; i < m; i++)
- { Console.Write(secondArr[i] + " "); }
- Console.WriteLine();
- Console.WriteLine("Equal elements: ");
- Console.WriteLine();
- IEnumerable<int> en = firstArr.Intersect(secondArr);
- int[] thirdArr = en.ToArray();
- int max = thirdArr[0];
- for (int i = 0; i < thirdArr.Length; i++)
- {
- Console.Write(thirdArr[i] + " ");
- if (thirdArr[i] > max)
- {
- max = thirdArr[i];
- }
- }
- Console.WriteLine();
- Console.WriteLine("The maximum value from the equal elements is: {0}", max);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement