Skip to content

Instantly share code, notes, and snippets.

@IvanNikolov
Created October 15, 2014 10:42
Show Gist options
  • Save IvanNikolov/6f47b609cab92e11bfda to your computer and use it in GitHub Desktop.
Save IvanNikolov/6f47b609cab92e11bfda to your computer and use it in GitHub Desktop.
using System;
//Write an if-statement that takes two doubleeger variables a and b
//and exchanges their values if the first one is greater than the second one. As a result prdouble the values a and b, separated by a space. Examples:
// b result
//5 2 2 5
//3 4 3 4
//5.5 4.5 4.5 5.5
class ExchangeIfGreater
{
static void Main()
{
//double used as to cover the 3 condition in the example.
double a = double.Parse(Console.ReadLine());
double b = double.Parse(Console.ReadLine());
double c = a;
if (a > b)
{
a = b; // XOR algorithm
b = c; //a = a ^ b;
//b = a ^ b;
//a = a ^ b;
Console.WriteLine(a+""+b);
}
else
{
Console.WriteLine(a+""+b);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment