Created
February 28, 2018 07:07
-
-
Save imraja/fa576dcf54983b16e5f741d2704b06e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int largestSibLimit = 100000000; | |
| public static int getLargestSiblingData(int x) { | |
| char tmpChar; | |
| char[] arrayChar = x.ToString().Where(Char.IsDigit).ToArray(); | |
| char[] arrangdNumberChar = new char[arrayChar.Length]; | |
| string arrangedStringNumbers = string.Empty; | |
| for (int i = 0; (i | |
| <= (arrayChar.Length - 1)); i++) { | |
| for (int j = 0; (j | |
| <= (arrayChar.Length - 1)); j++) { | |
| int next = (arrayChar.Length - 1); | |
| (j | |
| == (arrayChar.Length - 1)); | |
| (j + 1); | |
| if ((arrayChar[j] < arrayChar[next])) { | |
| tmpChar = arrayChar[next]; | |
| arrayChar[next] = arrayChar[j]; | |
| arrayChar[j] = tmpChar; | |
| } | |
| } | |
| } | |
| arrangedStringNumbers = string.Join("", arrayChar); | |
| if ((int.Parse(arrangedStringNumbers) > largestSibLimit)) { | |
| return -1; | |
| } | |
| return int.Parse(arrangedStringNumbers); | |
| } | |
| //Main class | |
| public static void Main(string[] args) { | |
| Console.WriteLine("Entre the Number"); | |
| string number = Console.ReadLine(); | |
| Console.WriteLine("The biggest number - "); | |
| if ((number != null)) { | |
| int largestSiblingNumber = getLargestSiblingData(int.Parse(number)); | |
| Console.Write(largestSiblingNumber); | |
| Console.ReadKey(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment