Advertisement
TodorovH

ExchangeIfGreater

Mar 28th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System;
  2.  
  3. // Write an if-statement that takes two integer variables a and b and 
  4. // exchanges their values if the first one is greater than the second one.
  5. // As a result print the values a and b, separated by a space.
  6.  
  7. class ExchangeIfGreater
  8. {
  9. static void Main()
  10. {
  11. Console.Write("Enter a value for a: ");
  12. double a = double.Parse(Console.ReadLine());
  13. Console.WriteLine();
  14. Console.Write("Enter a value for b: ");
  15. double b = double.Parse(Console.ReadLine());
  16. bool decimalpointA = Convert.ToString(a).IndexOf(".") > 0;
  17. bool decimalpointB = Convert.ToString(b).IndexOf(".") > 0;
  18. if ((decimalpointA == false) && (decimalpointB == false))
  19. {
  20. if (a > b)
  21. {
  22. a = a + b;
  23. b = a - b;
  24. a = a - b;
  25. Console.WriteLine();
  26. Console.WriteLine("{0} {1}", a, b);
  27. Console.WriteLine();
  28. }
  29. else
  30. {
  31. Console.WriteLine();
  32. Console.WriteLine("{0} {1}", a, b);
  33. Console.WriteLine();
  34. }
  35. }
  36. else
  37. {
  38. Console.WriteLine();
  39. Console.WriteLine("{0} {1}", a, b);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement