write a program to print the value of two integers before and after swapping without using a third variable
Answers
Answered by
0
Answer:
#include <iostream.h>
int main()
{
int a=5, b=10;
cout<<"Before swap a= "<<a<<" b= "<<b<<endl;
a=a*b; //a=50 (5*10)
b=a/b; //b=5 (50/10)
a=a/b; //a=10 (50/5)
cout<<"After swap a= "<<a<<" b= "<<b<<endl;
return 0;
}
Output:
Before swap a= 5 b= 10
After swap a= 10 b= 5
Similar questions
Computer Science,
5 months ago
Math,
5 months ago
History,
5 months ago
Chemistry,
1 year ago
Geography,
1 year ago