Advertisement
kuruku

ExchangeValues

Apr 16th, 2014
101
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. //Declare two integer variables a and b and assign them with 5 and 10 and after that exchange
  4. //their values. Print the variable values before and after the exchange
  5.  
  6. class ExchangeValues
  7. {
  8.     static void Main()
  9.     {
  10.         int firstValue = 5;
  11.         Console.WriteLine("a = {0}", firstValue);
  12.  
  13.         int secondValue = 10;
  14.         Console.WriteLine("b = {0}",secondValue);
  15.  
  16.         firstValue = firstValue + secondValue; // a = 15
  17.  
  18.         secondValue = firstValue - secondValue; // b = 5
  19.         Console.WriteLine("b = {0}", secondValue);
  20.  
  21.         firstValue = firstValue - secondValue; // a = 10
  22.         Console.WriteLine("a = {0}", firstValue);
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement