Python Program To Find Sum Of Two Numbers Without Using Arithmetic Operators


example 1:-

 def add_without_plus_operator(a, b):

    while b != 0:
        data = a & b
        a = a ^ b
        b = data << 1
    return a
print(add_without_plus_operator(2, 10))
print(add_without_plus_operator(-20, 10))
print(add_without_plus_operator(-10, -20))

output:-
12
-10
-30
>>> 


example 2:-

num1=10
num2=5
while num2 !=0:
        count=num1 & num2
        num1=num1^num2
        num2=count << 1
        
print("Sum of two numbers are",num1)
output:-
Sum of two numbers are 15
>>> 

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post