C# : Program to show swapping of two numbers

In this simple C# tutorial we were showing swapping between two numbers. Here we take "float" datatype, you can also take "int" or "double" datatype too depending on the number entered by the user. Here we are taking three variables "a" for number one and "b" for number two and "temp" i.e third variable to store our numbers during swapping. Now, lets get started!!

using System;
​class sum
{
 public static void Main(String []args)
 {
        float a,b,temp;
        Console.WriteLine("Enter value of a:");
        a=Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter value of b:");
        b=Convert.ToInt32(Console.ReadLine());
        temp=a;
        a=b;
        b=temp;
        Console.WriteLine("After swapping value of a is "+ a );
        Console.WriteLine("After swapping value of b is "+ b );
 }
}
SHARE

Raunak Hajela

Hi. I’m CEO/Founder of Kodestat. I’m Student, Geek, Web Designer, Developer, Blog Enthusiast and Player. Inspired to make things looks better. I like playing with codes plus I am marvel fan :-P You can check my design portfolio here. For consulation fell free to drop an email at raunakhajela@gmail.com.

  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment