C++ program to swap two entered numbers using macros

swap two entered numbers using macros

C++ program to swap two entered numbers using macros . Swaping means changing the values of a variable. Here the program will swap without using third variable.

#include<iostream.h>
#include<conio.h>
#define swap(x,y){x=x+y;y=x-y;x=x-y;}
void main()
{
clrscr();
int a,b;
cout<<"Enter value of a:- ";
cin>>a;
cout<<"Enter value of b:- ";
cin>>b;
swap(a,b);
cout<<"Value of a after swaping:- "<<a<<endl;
cout<<"Value of b after swaping:- "<<b<<endl;
getch();
}

OUTPUT

swap two entered numbers using macros


Comment below if you are facing any problem


Also read

Program to find cube of entered number using macros
C++ program swap two numbers using single inheritance
C++ program to find greatest between three numbers using single inheritance
C++ program to print alternate elements from an array
C++ program to Insert an element Into sorted array
C++ program to Sort the Entered Element in array


Leave a Reply

Your email address will not be published. Required fields are marked *