VelizarAvramov

07. Exchange Variable Values

Nov 28th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _07._Exchange_Variable_Values
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int a = int.Parse(Console.ReadLine());   // 5
  10.             int b = int.Parse(Console.ReadLine());   // 10
  11.  
  12.             Console.WriteLine("Before:");
  13.             Console.WriteLine($"a = {a}");
  14.             Console.WriteLine($"b = {b}");
  15.  
  16.             int temp = a;                         // temp = 5
  17.             a = b;                                // รก = 10
  18.             b = temp;                             // b = 5
  19.  
  20.             Console.WriteLine("After:");
  21.             Console.WriteLine($"a = {a}");
  22.             Console.WriteLine($"b = {b}");
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment