We have two names, say “AMITABH BACHCHAN ” and “RAJNIKANTH”. Our work is find common alphabet in these two names. The answer would be ‘AITHN’. i have written my code, if you find your code, more easier than mine, please do write in comment box. So lets go!
If you are looking for the solution in C/C++. Please visit Here .
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace commonAlpha { class Program { static void Main(string[] args) { char[] name1 = {'A','M','I','T','A','B','H','B','A','C','H','C','H','A','N'}; char[] name2 = { 'R', 'A', 'J', 'N', 'I', 'K', 'A', 'N', 'T', 'H' }; StringBuilder s1 = new StringBuilder(); for (int i = 0; i<name1.Count(); i++) { for (int j = 0; j < name2.Count(); j++) { //compareing two char from both string if (name1[i] == name2[j]) { char temp = name2[j]; if (s1.Length != 0) { int flag = 0; //checking whether its already in s1 or not. If yes, flag will be greater than 0 or if not flag=0 for (int k = 0; k < s1.Length; k++) { if (s1[k] == temp) flag++; } //confirm that temp is not in s1 if (flag == 0) { s1.Append(temp); } } else s1.Append(temp); } } } for (int i = 0; i < s1.Length; i++) Console.Write(s1[i]); Console.ReadLine(); } } }
Copyright © 2013 ·All Rights Reserved · Republishing or copying this article or any part of this without giving reference would come under WordPress Copyright Act.
If you liked this article, please rate and comment. Thank You!
Signature
Deepesh Singh
You may also like.
![]() |
![]() |
![]() |