Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class greaterOfTwo
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Please enter the first number:");
- int a;
- int.TryParse(Console.ReadLine(), out a);
- Console.WriteLine("Please enter the second number:");
- int b;
- int.TryParse(Console.ReadLine(), out b);
- int c = a - b;// We calculate the difference of the to numbers.
- int k = (c >> 31) & 1;// Using the bitwise operator to move the senior bit to the first position and then we & it with 1(which first bit is also 1) to make k 1 or 0;
- int max = a - k * c;// here if a < b, k is 1 --> a - 1 * c = a - c(but c = a - b, remember?), so a - (a - b) = b!!! Then we give that value to MAX.
- Console.WriteLine("The greatest of " + a + " and " + b + " is: " + max);// And in the end we print MAX
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement