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
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
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
Suggested for you
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…
View Comments
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 <>>
That's it...
It seems something is missing!
And, the source code you provided is wrong.
Thanks...
I hope you'll correct it.
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",num1)