Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 28 March 2017

Simple program


Simple program #5 (Swap number using two 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 two numbers.
 
Simple program #5 by www.imaginationhunt.com
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 Simple5   //swap number using two 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());
            Console.WriteLine();

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

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

            Console.ReadKey();
        }
    }
}

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.

Skip to Main Table Simple program

Previous - Simple program #4

Next – Simple program #6

Click imagination hunt to read latest blogs.


Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...