Write a program in C++ to swap two variables without using third variable

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

int main() {   
    int a=10, b=15;
    
    a = a+b;
    b = a-b;
    a = a-b;
    
    cout << "a:" << a << endl;
    cout << "b:" << b << endl;
      
    getch();
    return 0;
}

Output:

Leave a Reply

Contact Form

Name

Email *

Message *

Followers