Add two numbers using ++ and / or | C ++ program to add two numbers using ++ ; Returns value of x + y without using + ; If y is positive , y times add 1 to x ; If y is negative , y times subtract 1 from x ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int add ( int x , int y ) { while ( y > 0 && y -- ) x ++ ; while ( y < 0 && y ++ ) x -- ; return x ; } int main ( ) { cout << add ( 43 , 23 ) << endl ; cout << add ( 43 , -23 ) << endl ; return 0 ; }