Advertisement
kirililchev3

Exchange Variable Values

May 26th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P07_ExchangeVariableValues
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int num1 = int.Parse(Console.ReadLine());
  10.             int num2 = int.Parse(Console.ReadLine());
  11.             bool isBefore = true;
  12.             OutputTwoNumbers(num1, num2, isBefore);
  13.             SwapIntValues(ref num1, ref num2, ref isBefore);
  14.            
  15.         }
  16.         static void OutputTwoNumbers(int num1, int num2, bool isBefore)
  17.         {
  18.             Console.WriteLine("Before:");
  19.             Console.WriteLine($"a = {num1}");
  20.             Console.WriteLine($"b = {num2}");
  21.         }
  22.         static void SwapIntValues (ref int num1, ref int num2, ref bool isBefore)
  23.         {
  24.             Console.WriteLine("After:");
  25.             Console.WriteLine($"a = {num2}");
  26.             Console.WriteLine($"b = {num1}");
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement