VyaraG

ExchangeIfGreater

Nov 29th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2.  
  3. //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.
  4.  
  5. class ExchangeIfGreater
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         Console.Write("Enter an doubleeger number: ");
  10.         double a = double.Parse(Console.ReadLine());
  11.         Console.Write("Enter a second doubleeger number: ");
  12.         double b = double.Parse(Console.ReadLine());
  13.         bool aGreaterB = a > b;
  14.         if (aGreaterB)
  15.         {
  16.             Console.WriteLine(b +" "+ a);
  17.         }
  18.         else
  19.             Console.WriteLine(a+" "+b);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment