write a program input 2 number swap them without third variable
Answers
Answered by
2
hope you don't mind which programming language
here is the logic
let inputs be a and b
a=a+b
b=a-b
a=a-b
now the numbers will be swapped.
eg:
sample input
a=20
b=10
a=a+b /// now a=30,b=10
b=a-b /// now a=30,b=20
a=a-b /// now a=10, b=20
here is the logic
let inputs be a and b
a=a+b
b=a-b
a=a-b
now the numbers will be swapped.
eg:
sample input
a=20
b=10
a=a+b /// now a=30,b=10
b=a-b /// now a=30,b=20
a=a-b /// now a=10, b=20
Answered by
1
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,b;
cout<< '' Enter the variable a'';
cin>>a;
cout<< '' Enter the variable b'';
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<''The numbers after swapping is"<<"a="<<a<<"b="<<b;
getch();
}
hope its correct and you like it
please mark as brainliest
#include<conio.h>
using namespace std;
int main()
{
int a,b;
cout<< '' Enter the variable a'';
cin>>a;
cout<< '' Enter the variable b'';
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<''The numbers after swapping is"<<"a="<<a<<"b="<<b;
getch();
}
hope its correct and you like it
please mark as brainliest
AKumarDas:
done in c++ dev
Similar questions