Sunday, December 7, 2025
HomeLanguagesPython Program to find the Quotient and Remainder of two numbers

Python Program to find the Quotient and Remainder of two numbers

Given two numbers n and m. The task is to find the quotient and remainder of two numbers by dividing n by m.

Examples:

Input:
n = 10
m = 3
Output:
Quotient:  3
Remainder 1

Input
n = 99
m = 5
Output:
Quotient:  19
Remainder 4

Method 1: Naive approach

The naive approach is to find the quotient using the double division (//) operator and remainder using the modulus (%) operator.

Example:

Python3




# Python program to find the
# quotient and remainder
 
def find(n, m):
     
    # for quotient
    q = n//m
    print("Quotient: ", q)
     
    # for remainder
    r = n%m
    print("Remainder", r)
     
# Driver Code
find(10, 3)
find(99, 5)


Output:

Quotient:  3
Remainder 1
Quotient:  19
Remainder 4

Time Complexity: O(1)

Auxiliary Space: O(1)

Method 2: Using divmod() method

Divmod() method takes two numbers as parameters and returns the tuple containing both quotient and remainder.

Example:

Python3




# Python program to find the
# quotient and remainder using
# divmod() method
 
 
q, r = divmod(10, 3)
print("Quotient: ", q)
print("Remainder: ", r)
 
q, r = divmod(99, 5)
print("Quotient: ", q)
print("Remainder: ", r)


Output:

Quotient:  3
Remainder 1
Quotient:  19
Remainder 4

Time Complexity: O(1)

Auxiliary Space: O(1)

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32429 POSTS0 COMMENTS
Milvus
103 POSTS0 COMMENTS
Nango Kala
6803 POSTS0 COMMENTS
Nicole Veronica
11945 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12015 POSTS0 COMMENTS
Shaida Kate Naidoo
6934 POSTS0 COMMENTS
Ted Musemwa
7189 POSTS0 COMMENTS
Thapelo Manthata
6883 POSTS0 COMMENTS
Umr Jansen
6869 POSTS0 COMMENTS