Sunday, 4 January 2015

Cpp Program for Swapping of 2 numbers


This is a Cpp program which swaps the given 2 numbers . Here we use a temporary variable to perform swapping.


PROGRAM :


#include <iostream>

using namespace std;

int main()
{
    int num1,num2,temp_num;
    cout << "Enter 1st number : \t" ;
    cin >> num1;
    cout << "\n Enter 2nd number : \t";
    cin >> num2;

    cout << "\nThe numbers before swapping : \t" << num1 << "\t"<< num2 << endl;

    temp_num=num1;
    num1=num2;
    num2=temp_num;

    cout << " \nThe numbers after swapping : \t" << num1 << "\t"<< num2 << endl;
    return 0;
}
OUTPUT :


Cpp - Swapping