Advertisement
kuruku

ExchangeValueIfGreater

Apr 19th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2.  
  3. //Write an if-statement that takes two integer variables a and b and exchanges their values
  4. //if the first one is greater than the second one. As a result print the values a and b,
  5. //separated by a space.
  6.  
  7. class ExchangeValueIfGreater
  8. {
  9.     static void Main()
  10.     {
  11.         Console.Write("FirstValue = ");
  12.         double firstValue = double.Parse(Console.ReadLine());
  13.         Console.Write("SecondValue = ");
  14.         double secondValue = double.Parse(Console.ReadLine());
  15.         double thirdValue = 0;
  16.         if (firstValue > secondValue)
  17.         {
  18.             thirdValue = firstValue;
  19.             firstValue = secondValue;
  20.             secondValue = thirdValue;
  21.  
  22.         }
  23.         Console.WriteLine("{0} {1}", firstValue, secondValue);
  24.  
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement