WAP to swap two numbers without using temporary or third variable?
1
Expert's answer
2013-03-15T10:00:10-0400
#include <iostream>
int main() { //output std::cout<<"input number A : "; int a;//create variable std::cin>>a;//assign user inputed value to a variable std::cout<<"input number B : ";//output int b;//create variable std::cin>>b;//assign user inputed value to a variable
std::cout<<a<<" - "<<b<<std::endl;//outpiut values before swap
//swap a +=b; //a = a+b b = a-b;& // a-=b; //a = a-b
std::cout<<a<<" - "<<b<<std::endl; // output after swap
Comments
Leave a comment