### Simple program

Simple program #4 (Swap number using three variables)

Before swapping a is : 8
Before swapping b is : 6
After swapping a is : 6
After swapping b is : 8

The program is written in C# programming language and will accept two numbers as input. The logic of the program is to swap input number using three numbers.

 Simple program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code the program.

Practical Implementation:

using System;

namespace patternProblem.Simple_program
{
class Simple4   //swap number using three variables
{
static void Main(string[] args)
{
Console.Write("Enter first number: ");
int fn = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
int sn = Convert.ToInt32(Console.ReadLine());
int c = 0;
Console.WriteLine();

Console.WriteLine("-----Output-----");

Console.WriteLine();
Console.WriteLine("Before swapping a is : {0}", fn);
Console.WriteLine("Before swapping b is : {0}", sn);
c = fn;
fn = sn;
sn = c;
Console.WriteLine("After swapping a is : {0}", fn);
Console.WriteLine("After swapping b is : {0}", sn);

}
}
}

Output:
The first input number here is 5 and second input number is 2. The program will swap numbers. The output is shown below:

Enter first number: 5
Enter second number: 2

Before swapping a is: 5
Before swapping b is: 2
After swapping a is: 2
After swapping b is: 5
Press any key to continue . . .

For any query, comment us below.

Previous - Simple program #3

Next – Simple program #5

Click imagination hunt to read latest blogs.

Keep learning and sharing...