Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ Swap 2 Variables Without Using 3rd Variable

	int num1, num2, temp;
	cout << " Input 1st number : ";
	cin >> num1 ;
	cout << " Input 2nd number : ";
	cin >> num2;	
	num2=num2+num1;
	num1=num2-num1;
	num2=num2-num1;
    cout << " After swapping the 1st number is : "<< num1 <<"
" ; 
    cout << " After swapping the 2nd number is : "<< num2 <<"

" ; 	
 
PREVIOUS NEXT
Tagged: #Swap #Variables #Without #Using #Variable
ADD COMMENT
Topic
Name
1+5 =