This Python program reads two integers from the user and simulates division using repeated subtraction.
Instead of using the / operator, it subtracts the smaller number from the larger one until the remainder is less than the divisor.
The number of subtractions equals the quotient.
# Read two numbers from user
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
# Check for division by zero
if b == 0:
print("Error: Division by zero is not allowed.")
else:
# Identify dividend and divisor
dividend = max(a, b)
divisor = min(a, b)
# Perform division using subtraction
quotient = 0
remainder = dividend
while remainder >= divisor:
remainder -= divisor
quotient += 1
# Display result
print("\n--- Result ---")
print(f"{dividend} divided by {divisor} = {quotient} with remainder {remainder}")
Enter the first number: 8
Enter the second number: 2
--- Result ---
8 divided by 2 = 4 with remainder 0
- The user enters two integers
- The larger number is treated as the dividend, the smaller as the divisor
- The program subtracts the divisor from the dividend repeatedly
- Each subtraction increments the quotient
- When the remainder becomes less than the divisor, the loop stops
- The final result includes both quotient and remainder