Showing posts with label Swap two values using third variable.. Show all posts
Showing posts with label Swap two values using third variable.. Show all posts

Sunday, September 3, 2017

Swap two values using third variable.

Swap two values using third variable.


using System;
class swaping
{
         
       public static void Main(string[] args)
       {
         int a,b,temp;
         Console.WriteLine("Enter the value for a");
         a=Convert.ToInt32(Console.ReadLine());

         Console.WriteLine("Enter the value for b");
          b=Convert.ToInt32(Console.ReadLine());
          Console.WriteLine("Before swaping valus are:-");
         Console.WriteLine("a=" +a);
         Console.WriteLine("b="+b);
          temp=a;
          a=b;
          b=temp;
 
         Console.WriteLine("After swaping valus are:-");
         Console.WriteLine("a=" +a);
         Console.WriteLine("b="+b);
         Console.Read();

       }
}


Output:

Before:-

a=1
b=2

After:-

a=2
b=1