Logic of the code:
C++ program code to swap the values of two integer:
#include<iostream>
using namespace std;
int main()
{
int var1, var2, swap;
cout<<"Enter value for first integer: ";
cin>>var1;
cout<<"Enter value for second integer: ";
cin>>var2;
cout<<" Values Before swapping: "<<endl;
cout<<"First Integer ="<<var1<<endl;
cout<<"Second Interger ="<<var2<<endl;
swap=var1;
var1=var2;
var2=swap;
cout<<" Values After swapping: "<<endl;
cout<<"First Integer ="<<var1<<endl;
cout<<"Second Interger ="<<var2<<endl;
return 0;
}Sample Output:
Image of Code:
- Take three variables var1,var2 and swap.
- Store value of var1 in swap.
- Store value of var2 in var1.
- Copy value of swap into var2 which is value of var1.
C++ program code to swap the values of two integer:
#include<iostream>
using namespace std;
int main()
{
int var1, var2, swap;
cout<<"Enter value for first integer: ";
cin>>var1;
cout<<"Enter value for second integer: ";
cin>>var2;
cout<<" Values Before swapping: "<<endl;
cout<<"First Integer ="<<var1<<endl;
cout<<"Second Interger ="<<var2<<endl;
swap=var1;
var1=var2;
var2=swap;
cout<<" Values After swapping: "<<endl;
cout<<"First Integer ="<<var1<<endl;
cout<<"Second Interger ="<<var2<<endl;
return 0;
}Sample Output:
Image of Code:
int a = 5, b = 3;
ReplyDeletestd::swap(a, b);
Swap=int a;
DeleteInt a= Int b;
Swap= Int b;
Swap=int a;
DeleteInt a= Int b;
Swap= Int b;
can anybody write swap in turbo c++
ReplyDeleteSwap=int a;
ReplyDeleteInt a= Int b;
Swap= Int b;