Skip to content

addition_without_arithmetic #6830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 30, 2022
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions maths/Addition_without_arithmetic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Illustrate how to add the integer without arithmetic operation
Author: suraj Kumar
Time Complexity: 1
"""


first = int(input("Enter the number for first: "))
sec = int(input("Enter the number for sec: "))


def add(first, sec) -> int: # Create a function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide type hint for the parameter: first

Please provide type hint for the parameter: sec

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide type hint for the parameter: first

Please provide type hint for the parameter: sec

"""
implementation of addition of integer
:param first: int
:param sec: int
:return: int
Examples:
>>> add(3,5)
8
>>> add(13,5)
18
"""
while sec != 0:

c = first & sec

first = first ^ sec

sec = c << 1
return first


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