Computer Science, asked by aboutscience710, 19 days ago

Program to swap the values of two variables by the using the if-else statement in c++​

Answers

Answered by thinkofmaster1974
2

Answer:

#include<iostream>

using namespace std;

int main ()

{

int a,b;

cout<<"enter two numbers"<<endl;

cin>>a>>b;

if(a!=b)

{

a=a+b;

b=a-b;

a=a-b;

cout<< "After swapping the values,"<<"value of a is:"<<a<<"and value of b is:"<<b;

}

else

cout<<"two number are eqaul";

}

Explanation:

hope it helps

plz mark me as brainlist

Answered by madshadow
1
#include
using namespace std;

int main()
{
int a = 5, b = 10, temp;

cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;

temp = a;
a = b;
b = temp;

cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;

return 0;
}
Similar questions