Advertisement
AnitaN

05.ConditionalStatementsHomework/01.ExchangeIfGreater

Mar 29th, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. //Problem 1.    Exchange If Greater
  2. //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. Examples:
  3.  
  4. using System;
  5.  
  6. class ExchangeIfGreater
  7. {
  8.     static void Main()
  9.     {
  10.         Console.Write("Please, enter a:");
  11.         double a = double.Parse(Console.ReadLine());
  12.         Console.Write("Please, enter b:");
  13.         double b = double.Parse(Console.ReadLine());
  14.         if (a > b)
  15.         {
  16.             Console.WriteLine("Exchange needed:{0} <===> {1}",a,b);
  17.             double greaterNumber = a;
  18.             a=b;
  19.             b=greaterNumber;
  20.             Console.WriteLine(a + " " + b);
  21.         }
  22.         else
  23.         {
  24.             Console.WriteLine("No Exchange needed:{0} <===> {1}",a,b);
  25.             Console.WriteLine(a + " " + b);
  26.         }      
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement