/*Without using any third varible*/
#include<iostream.h>
#include<iostream.h>
Using namespace std
void main()
{
int a,b ;
a=1 ;
b=2 ;
SwapInC++(a , b) ; //swap function call
Cout<<"values after swap a= "<< a <<endl ;
Cout<<"values after swap b= "<< b <<endl ;
} //End of main
void SwapInC++(int x,int y) //definition
of Swap functon
{
y= x-y+(x=y);
}
Common Programming Error:-
C++ compiler read from left to right to do not Confound with swap logic.
Good Programming Practice:-
always use equation like here i used instead using another temporary storage.
Common Programming Error:-
C++ compiler read from left to right to do not Confound with swap logic.
Good Programming Practice:-
always use equation like here i used instead using another temporary storage.
No comments:
Post a Comment