Calculations

Python Example to subtract two integer without using minus operator

Python Example to subtract two integer without using minus operator

In this article, we will discuss the concept of the Python Example to subtract two integer without using minus operator

In this post, we are going to learn how to  write a program to find the subtraction of two numbers with out using minus operator in Python programming language

subtract two integer without minus

Code to find the subtraction of  two numbers 

Subtract two integer using without minus

The program use to calculate subtraction of given two integer numbers using without minus operator in Python language

Program 1

num1=200#variable declaration
num2=75
sub=num1+(~num2+1)
#calculate subtraction without minus
print('The subtraction of {0} and {1} is: {2}'.format(num1, num2, sub))
#display output

When the above code is executed, it produces the following result

The subtraction of 200 and 75 is: 125

 

Subtract two integer using without minus – takes user input

Program 2

The program allow the user to enter two numbers and then calculates subtraction of given two integer numbers using without minus operator in Python language

num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
#ask input from the user
#two input are stored in variable num1,num2 respectively
sub=num1+(~num2+1)
#calculate subtraction using without minus
print('The subtraction of {0} and {1} is: {2}'.format(num1, num2, sub))
#display output on the screen

When the above code is executed, it produces the following result

case 1

Enter first number: 1000
Enter second number: 400
The subtraction of 1000 and 400 is: 600

 

Case 2

Enter first number: 400
Enter second number: 1000
The subtraction of 400 and 1000 is: -600

 

Suggested for you

Operator in Python language

Data type in python language

if statements in Python language

function in Python language

 

Similar post

Subtract two numbers in Java language

Subtract two numbers using method in Java language

Subtract two numbers using recursion in Java language

Find sum of two numbers in Java

Find sum of two numbers in Java using recursion

Find sum of two numbers in Java without Arithmetic operator

Find sum of natural numbers in Java language

Find sum of natural numbers in Java language using recursion

Java Example to subtract two integer without using minus operator
C Example to subtract two integer without using minus operator
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.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago