Question 13 of 22beginner🔧 ApplyLong Answer4 marks

Write a program to enter two integers and perform all arithmetic operations on them.

Correct Answer

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)

Exercise: EXERCISE | Q: 13 | (Page 32)
For More Understanding

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

  1. Step 1: Accept two integers as input using int(input())

  2. Step 2: Perform addition using + operator and display result

  3. Step 3: Perform subtraction using - operator and display result

  4. Step 4: Perform multiplication using * operator and display result

  5. Step 5: Perform division using / operator and display result

  6. Step 6: Perform modulus using % operator and display result

  7. Step 7: Perform floor division using // operator and display result