- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to add two numbers
In this article, we will learn about the solution and approach to solve the given problem statement.
We will be given two large numbers and we need to add them and display the output.
The bruteforce approach will be using the “+” operator between the operands or we can store two numbers in an iterable and use the inbuilt sum function available in Python standard library.
In this approach, time complexity is increased as the computation takes place on decimal numbers directly.
Now lets’s discuss another approach that involves working on the bits of the decimal numbers.
Here we will use the concept of adders that computes the sum and the carry .
Now let’s see the implementation −
def Add(x, y): # carry becomes null while (y != 0): # carry with common bits carry = x & y # Sum of bits of x and y x = x ^ y # Carry is shifted by one y = carry << 1 return x print(Add(19, 34))
All variables and functions are declared in the global scope as shown in the figure below.
In this article, we learned about the approach to add two numbers by the help of a full adder.
- C++ Program to Add Two Numbers
- Java Program to Add Two Numbers
- Add Two Numbers in Python
- Java Program to Add the two Numbers
- Java Program to Add Two Complex numbers
- Program to add two numbers represented as strings in Python
- 8051 Program to Add two 8 Bit numbers
- 8085 Program to Add two 8 Bit numbers
- 8085 program to add two 16 bit numbers
- Program to Add Two Complex Numbers in C
- 8085 Program to Add two multi-byte BCD numbers
- 8086 program to add two 8 bit BCD numbers
- Add two numbers represented by two arrays in C Program
- Program to Add two multi-byte numbers in 8085 Microprocessor
- Program to Add two 8 Bit numbers in 8085 Microprocessor