Write a program to enter two integers and perform all arithmetic operations on them.
Program to perform all arithmetic operations on two integers
num1 = int(input("Enter first integer: ")) num2 = int(input("Enter second integer: "))
Performing Addition
add = num1 + num2 print("Addition:", add)
Performing Subtraction
sub = num1 - num2 print("Subtraction:", sub)
Performing Multiplication
mul = num1 * num2 print("Multiplication:", mul)
Performing Division
div = num1 / num2 print("Division:", div)
Performing Modulus
mod = num1 % num2 print("Modulus:", mod)
Performing Floor Division
floor_div = num1 // num2 print("Floor Division:", floor_div)
Explanation
This program demonstrates all arithmetic operations on two integers. The addition operator (+) adds two numeric values. The subtraction operator (-) subtracts the right operand from the left. The multiplication operator (*) multiplies two values. The division operator (/) divides the left operand by the right and returns the quotient as a float. The modulus operator (%) returns the remainder after division. The floor division operator (//) performs division and returns the integer part of the quotient. The program uses int() for type conversion to ensure inputs are integers, and prints results for each operation.
Solution Steps
Step 1: Accept two integers as input using int(input())
Step 2: Perform addition using + operator and display result
Step 3: Perform subtraction using - operator and display result
Step 4: Perform multiplication using * operator and display result
Step 5: Perform division using / operator and display result
Step 6: Perform modulus using % operator and display result
Step 7: Perform floor division using // operator and display result