Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 02. Common Elements
- Write a program, which prints common elements in two arrays. You have to compare the elements of the second array to the elements of the first.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _02CommonElements
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] firstArray = Console.ReadLine().Split();
- string[] secondArray = Console.ReadLine().Split();
- string result = "";
- foreach (var firstWord in secondArray)
- {
- foreach (var nextWord in firstArray)
- {
- if (firstWord == nextWord)
- {
- result += firstWord + " ";
- }
- }
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment