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 ); } }
0 comments:
Post a Comment