Advertisement
sylviapsh

Exchange Two Integer Numbers If the First Is Bigger

Dec 28th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. class ExchangeTwoIntNumsIfFirstIsBigger
  3. {
  4.   static void Main()
  5.   {
  6. //Telerik Academy
  7.     //Write an if statement that examines two integer variables and exchanges their values if the first one is greater than the second one.
  8.  
  9.     Console.Write("Please enter the first integer number:");
  10.     int firstNum = int.Parse(Console.ReadLine());
  11.     Console.Write("Please enter the second integer number:");
  12.     int secondNum = int.Parse(Console.ReadLine());
  13.  
  14.     if (firstNum == secondNum)
  15.     {
  16.       Console.WriteLine("The first number is equal to the second one! {0} = {1}", firstNum, secondNum);
  17.     }
  18.     else if (firstNum < secondNum)
  19.     {
  20.       Console.WriteLine("The first number is smaller than the second one! {0} < {1}", firstNum, secondNum);
  21.     }
  22.     else if (firstNum > secondNum)
  23.     {
  24.       Console.WriteLine("The first number is bigger than the second one! {0} > {1}", firstNum, secondNum);
  25.       firstNum += secondNum;
  26.       secondNum = firstNum - secondNum;
  27.       firstNum -= secondNum;
  28.       Console.WriteLine("The first number is now equal to {0} and the second number is equal to {1}!", firstNum, secondNum);
  29.     }
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement