addition

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

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

  • User inputs the first number
  • Store  the number in variable a
  • User inputs the second number
  • Store the number in variable b
  • Create a function with “while loop” used for addtion of two numbers.
  • Call the function
  • Display the sum of the numbers on the screen.

 

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
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

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)

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago