Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // 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.
- class ExchangeIfGreater
- {
- static void Main()
- {
- Console.Write("Enter a value for a: ");
- double a = double.Parse(Console.ReadLine());
- Console.WriteLine();
- Console.Write("Enter a value for b: ");
- double b = double.Parse(Console.ReadLine());
- bool decimalpointA = Convert.ToString(a).IndexOf(".") > 0;
- bool decimalpointB = Convert.ToString(b).IndexOf(".") > 0;
- if ((decimalpointA == false) && (decimalpointB == false))
- {
- if (a > b)
- {
- a = a + b;
- b = a - b;
- a = a - b;
- Console.WriteLine();
- Console.WriteLine("{0} {1}", a, b);
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine();
- Console.WriteLine("{0} {1}", a, b);
- Console.WriteLine();
- }
- }
- else
- {
- Console.WriteLine();
- Console.WriteLine("{0} {1}", a, b);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement