63 206
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #26378 in C++ for pinak

Question #26378
WAP to swap two numbers without using temporary or third variable?
Expert's answer
#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

std::cin.get();//suspend console
std::cin.get();//suspend console
return 0;//exit
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions