Write a program in C# to swap two numbers.
Sample Output
Sample Solution
C# Sharp Codeusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class intercharge { int top_score; int New_score; int temp; void Swap() { Console.Write("Enter Top Score : "); top_score = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter New Score : "); New_score = Convert.ToInt32(Console.ReadLine()); temp = top_score; top_score = New_score; New_score = temp; } void Display() { Console.WriteLine("\n After swapping \n"); Console.WriteLine(" The new value of top score is :{0}",top_score); Console.WriteLine(" The old value of top score is :{0}",New_score); } static void Main(string[] args) { intercharge obj = new intercharge(); obj.Swap(); obj.Display(); Console.ReadLine(); } } }
Sample Output
No comments:
Post a Comment