Computer Science, asked by ashkhan78, 11 months ago

write a program that asks the user to type 2 integers A and B and exchange the value of A and B ?​

Answers

Answered by techtro
1

The first variable's contents are copied into the temp variable. The second variable's contents are then copied to the first variable.

#include<iostream>

using namespace std;

int main()

{

double a,b,temp;

cout<<"Type the value of a : ";cin>>a;

cout<<"Type the value of b : ";cin>>b;

temp=a;

a=b;

b=temp;

cout<<"The value of a is "<<a<<endl;

cout<<"The value of b is "<<b<<endl;

return 0;

}

Expected Output

Before Swapping -> a=10, b =15

After Swapping -> a=15, b=5

Answered by Sidyandex
0

Answer:

The first variable's contents are copied into the temp variable.

The second variable's contents are then copied to the first variable.

#include<iostream>using namespace std;int main(){double a,b,temp; cout<<"Type the value of a : ";cin>>a; cout<<"Type the value of b : ";cin>>b; temp=a; a=b; b=temp; cout<<"The value of a is "<<a<<endl; cout<<"The value of b is "<<b<<endl; return 0;} Expected Output.Before Swapping -> a=10, b =15.

After Swapping -> a=15, b=5.

Similar questions