c++ program to swap two variable WITHOUT using third variable

 C++ Program for swaping the values of two variables using third variable.
 It means that the following code will interchange the values of two varibles.
 Author of this program. Jayant Purohit.
 Company www.cyberoceanz.com   
 For more porgrames visit   www.glanceatc.blogspot.com


#include <iostream.h>
#include <conio.h>

void main()
{
    int first,second;    // two variables declared here.
    clrscr();
    first=25;                // value of the first varible is assigned here;
    second=45;                // value of the second varible is assigned here;

    cout<<"\nvalue of the first variable before swapping is :->"<<first;
    cout<<"\nvalue of the second variable before swapping is :->"<<second;

    first=first+second;
    second=first-second;
    first=first-second;

    cout<<"\nvalue of the first variable after swapping is :->"<<first;
    cout<<"\nvalue of the second variable after swapping is :->"<<second;

    getch();
}
if you have any problem then please feel free to post your comment in the comment box below the post.

Get more News to increase your GK. for campus and competitive Exams.






Pageviews last month