Search This Blog

Wednesday 28 January 2015

Sibling number and get largest number in the family using C#

Following code will illustrate to get largest number from given sibling numbers.

static void Main(string[] args)
        {
            int n2 = 3456789;
            var digits = new List<int>();
            int temp = 0;
            for (; n2 != 0; n2 /= 10)
            {
                digits.Add(n2 % 10);
            }
            var arr2 = digits;
            for (int num = 0; num < arr2.Count; num++)
            {
                for (int sort = 0; sort < arr2.Count - 1; sort++)
                {
                    if (arr2[sort] < arr2[sort + 1])
                    {
                        temp = arr2[sort + 1];
                        arr2[sort + 1] = arr2[sort];
                        arr2[sort] = temp;
                    }
                }
            }

            for (int i = 0; i < arr2.Count; i++)
                Console.Write(arr2[i] + "");
            Console.ReadKey();
        }

Sibling number and get largest number in the family using C#

No comments:

Post a Comment