Swapp of two numbers without using 3rd variable

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 690
In this Code Snippet we will know how to swap of two numbers without using 3rd variable. 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Swapp_two_number_without_3rd_var
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int a;
int b;
a = 1;
b = 2;
MessageBox.Show("Original numbers are" + a + ":"+ + b);
a = a + b;
b = a - b;
a = a - b;
MessageBox.Show("Swapping numbers are" + a + ":" + +b);
}
}
}

Comments or Responses

Login to post response