0
Write ac++ that swaps two numbers using atemporary or third variable , the output shoyld be as below for anum1=5 and num2=8 ???
before swaping value of num1 is 5 value of num is 8 after swaping value of num1 is 8 value of num2 is 5 2) re_type the program to swap the value without using athird variable ??
1 Réponse
+ 2
You need to pass your variables by reference to the function to modify them directly inside it.
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
void swap2(int &a, int &b) {
a = a + b;
b = a - b;
a = a - b;
}