76 273
Assignments Done
Successfully Done
In May 2019

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()
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

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions