Q: Exchange if greater (task in C#)

+4 votes

Write an if-statement that takes two integer variables a and b and exchanges their values if the first one is greater than the second one. As a result print the values a and b, separated by a space.


exchange if greater task in C#

asked in C# category by user eiorgert
edited by user golearnweb

1 Answer

+1 vote
Best answer

Here's how I did this task:

using System;

class ExchangeIfGreater
    static void Main()
        decimal a = decimal.Parse(Console.ReadLine());
        decimal b = decimal.Parse(Console.ReadLine());

        if (a > b)
            Console.WriteLine("{0} {1}", b, a);
            Console.WriteLine("{0} {1}", a, b);
answered by user samfred5830
selected by user golearnweb