It is very useful program for swapping of two number.
I have also another code for the same
Console.Writeline("Enter the First Number : "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter the Second Number : "); num2 = Convert.ToInt32(Console.ReadLine()); num2=num1*num2/(num1=num2); Console.WriteLine(" number1 : {0} number2 : {1}", num1, num2);\
It is a program to swap two number without using the 3rd variable.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main(string[] args) int num1, num2; string y; do { Console.Write("Enter the First Number : "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter the Second Number : "); num2 = Convert.ToInt32(Console.ReadLine()); num1 = num1 + num2; num2 = num1 - num2; num1 = num1 - num2; Console.WriteLine("Swapping is completed \n 1st number is {0} \n 2nd number is {1}", num1, num2);
Console.WriteLine("Do you want to Repeat Y/N \n"); y = Console.ReadLine(); Console.ReadLine(); } while (y == "y" || y == "Y"); if (y == "n" || y == "N") Console.WriteLine("Exiting the program"); else Console.WriteLine("You have entered wrong entry exiting the program"); Console.ReadLine(); } } }
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Console.Writeline("Enter the First Number : ");num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the Second Number : ");
num2 = Convert.ToInt32(Console.ReadLine());
num2=num1*num2/(num1=num2);
Console.WriteLine(" number1 : {0} number2 : {1}", num1, num2);\
It is a program to swap two number without using the 3rd variable.