In this article, we will discuss the concept of the Python code to Add two integer using without + operator
In this post, we are going to learn how to write a program to find the sum of two numbers using without plus operator in Python programming language
The program allows the user to enter two integers and then calculates the sum of given numbers using minus operator in Python language
Program 1
num1=int(input("Enter first number: ")) #ask input from user for num1 num2=int(input("Enter second number: ")) #ask input from user for num2 ans=num1-(-num2) #Calculate the addition print("Sum of two numbers is",ans) #display output on the screen
When the above code is executed, it produces the following result
Enter first number: 259 Enter second number: 245 Sum of two numbers is 504
The program allows the user to enter two integers and then calculates the sum of given numbers using Bitwise operator in Python language
Program 2
num1=int(input("Enter the first number: ")) #ask input from user for num1 num2=int(input("Enter the second number: ")) #ask input from user for num2 while num2 !=0: count=num1 & num2 num1=num1^num2 num2=count << 1 print("Sum of two numbers is",num1) #display result on the screen
When the above code is executed, it produces the following result
Enter the first number: 1000 Enter the second number: 300 Sum of two numbers is 1300
The program allows the user to enter two integers and then calculates the sum of given numbers using Bitwise operator with function in Python language
Program 3
num1=int(input("Enter first number: ")) num2=int(input("Enter second number: ")) def add_without_Plus(num1,num2):#function definition while num2 !=0: count=num1 & num2 num1=num1^num2 num2=count << 1 return num1 print("Sum of two numbers are",add_without_Plus(num1,num2)) #Calling the function and the result displays on the screen
When the above code is executed, it produces the following result
Enter first number: 1234 Enter second number: 4321 Sum of two numbers are 5555
Suggested for you
if statements in Python language
Similar post
Subtract two numbers in Python language
Subtract two numbers using function in Python language
Find sum of two numbers in Python Language
Find sum of two numbers in Python using recursion
Find sum of two numbers in Python without Arithmetic operator
Find sum of natural numbers in Python language
Find sum of natural numbers in Python language using recursion
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…