C# Examples
C# ExamplesPrograms with output

C# Program to Swap two Numbers


Example:
using System;

public class SwapNumbers  
{  
    public static void Main(string[] args)  
    {  
        int  num1=10, num2=20, swap;            
        Console.WriteLine("Before swap A: "+num1+" B: "+num2);    
        
        swap = num1;
		num1 = num2;
		num2 = swap;
		
        Console.Write("After swap A: "+num1+" B: "+num2);
        Console.ReadLine();
    }  
}
Output:
Before swap A: 10 B: 20
After swap A: 20 B: 10

Share this page on:

Was this page helpful ?

Let us know how we did!

Subscribe Email Updates

to get latest update