Codeforcoding

Python program to find sum of two numbers without using arithmetic operators

Python program to find sum of two numbers without using arithmetic operators

sum of two numbers without using arithmetic operators using function

In this tutorial, we will discuss the concept of Python program to find sum of  two numbers without using arithmetic operators

In this post, we will learn how to make the addition of two number using without the arithmetic operator in Python programming language

Python program to find sum of two numbers with out using arithmetic operators
Addition

Program 1

This program allows the user to enter two numbers and displays the sum of two numbers entered by the user

#Python program to add two numbers
#Without using arithmetic operator
a=int(input("Enter the number for a: "))
b=int(input("Enter the number for b: "))
def add(a,b):   #Create a function
    while(b != 0):#while loop

        c=a&b #and operator

        a=a^b #Xor operator

        b=c<<1
    return a

    
    
print("Sum of two numbers",add(a,b))  #call the function
#Display sum of two numbers

When the above code is executed, it produces the following results

Enter the number for a: 34
Enter the number for b: 54
Sum of two numbers 88

 

Methods

 

sum of two numbers without using arithmetic operators

Program 2

This program allows the user to enter two numbers and displays the sum of two numbers entered by the user

num1=int(input("Enter the first number"))
num2=int(input("Enter the second number"))
while num2 !=0:
        count=num1 & num2
        num1=num1^num2
        num2=count << 1
        
print("Sum of two numbers are",num1)

 

When the above code is executed, it produces the following results

Enter the first number: 123
Enter the second number: 345
Sum of two numbers are 468

 

Similar post

Python program to calculate the sum of two numbers

Python program to calculate the sum of two numbers using function

Python program to calculate sum of two numbers using recursion

 

Java program to find sum of two numbers without using arithmetic operators

C  program to find sum of two numbers without using arithmetic operators

C++ program to find sum of two numbers without using arithmetic operators

 

C program to add two numbers without using arithmetic operators

C++ program to add two numbers without using arithmetic operators

Python program to add two numbers without using arithmetic operators

Java program to sum of two numbers

C program to sum of two numbers

C++ program to sum of two numbers

Python program to sum of two numbers

C++ program to find the sum  of two numbers  using recursion

C program to find the sum  of two numbers  using recursion

Java program to find the sum  of two numbers  using recursion

Python program to find the sum  of two numbers  using recursion

 

 

 

Suggested for you

Python programming function

Python programming while loop

Python programming operator

Python programming datatype

Java program to add two numbers without using arithmetic operators
Java program to check whether a number is Positive or Negative or Zero
Exit mobile version