Write a Program in C++ to swap two integer numbers without and with using third variable | Ameer Yousuf - C++ Programs Codes

Latest

Sunday, 31 January 2021

Write a Program in C++ to swap two integer numbers without and with using third variable | Ameer Yousuf

 CODE:


#include<iostream>
using namespace std;
int main(){
int a,b;
cout<<"Enter the value of A: ";
cin>>a;
cout<<"Enter the value of B: ";
cin>>b;
cout<<"Before Swapping: \n";
cout<<"A : "<<a<<endl;
cout<<"B : "<<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"After Swapping: \n";
cout<<"A : "<<a<<endl;
cout<<"B : "<<b<<endl;
return 0;
}

OUTPUT:





No comments:

Post a Comment

Plz don't enter any spam link in the comment box!