Computer Science, asked by BrainlyHulk, 1 year ago

13 Points !!!

Write a Program that interchanges the value of two integers A and B without using extra variable.

C++ || Class 11 CBSE || Computer Science

Answers

Answered by aditya1984
1
#include<iostream>
using namespace std;

void swap(int &a, int &b)
{
b = a + b;
a = b - a;
b = b - a;
}

int main()
{
int a, b;

cout << "Enter two numbers to be swapped : ";
cin >> a >> b;

swap(a, b);

cout << "The two numbers after swapping become :" << endl;

cout << "Value of a : " << a << endl;
cout << "Value of b : " << b << endl;
}
Similar questions