How to sort three integers in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 2, b = 3, c = 1, tmp;

            Console.WriteLine("{0} {1} {2}", a, b, c);

            if (a > b)
            {
                tmp = a;
                a = b;
                b = tmp;
            }
            Console.WriteLine("{0} {1} {2}", a, b, c);
            if (b > c)
            {
                tmp = b;
                b = c;
                c = tmp;
            }
            Console.WriteLine("{0} {1} {2}", a, b, c);
            if (a > b)
            {
                tmp = a;
                a = b;
                b = tmp;
            }
            Console.WriteLine("{0} {1} {2}", a, b, c);
        }
    }
}


answered Apr 9, 2014 by avibootz
...