Program to find quotient and remainder of two numbers

Posted in

Program to find quotient and remainder of two numbers
vinaykhatri

Vinay Khatri
Last updated on December 21, 2024

    In this programming tutorial, we will write a program to find the quotient and remainder of two numbers. When we divide two numbers the result we get is the quotient, it is the number of times a division is divided completely. A remainder is a value that is left after division when the divisor could not divide the dividend completely.

    Algorithm

    1. To find the quotient in programming languages we use / operator
    2. And to find remainder we use % (modulo) operator.

    C Program to find quotient and remainder of two numbers

    #include <stido.h>
    int main() 
    {
        int dividend, divisor, quotient, remainder;
        
        //ask user to enter dividend and divisor
    	printf("Enter dividend and divisor (eg 20 5): ");
        scanf("%d %d", &dividend, &divisor);
        
    	quotient = dividend/divisor;
    	remainder = dividend%divisor;
    	
    	printf("The quotient is: %d \n", quotient);
    	printf("The remainder is: %d", remainder);
        return 0;
    }

    Output

    Enter dividend and divisor (eg 20 5): 50 4
    The quotient is: 12
    The remainder is: 2

    C++ Program to find quotient and remainder of two numbers

    #include <iostream>
    using namespace std;
    
    int main() 
    {
      	int dividend, divisor, quotient, remainder;
        
        //ask user to enter dividend and divisor
    	cout<<"Enter dividend and divisor (eg 20 5): "; cin>>dividend>> divisor;
        
    	quotient = dividend/divisor;
    	remainder = dividend%divisor;
    	
    	cout<<"The quotient is: "<< quotient<<endl;
    	cout<<"The remainder is: "<< remainder;
        return 0;
    }

    Output

    Enter dividend and divisor (eg 20 5): 60 30
    The quotient is: 2
    The remainder is: 0

    Python Program to find quotient and remainder of two numbers

    dividend, divisor = map(int, input("Enter dividend and divisor (eg 20 5): ").split())
    
    quotient = dividend//divisor
    remainder = dividend%divisor
    
    print("The Quotient is: ", quotient)
    print("The remainder is: ", remainder)

    Output

    Enter dividend and divisor (eg 20 5): 50 6
    The Quotient is: 8
    The remainder is: 2

    Conclusion

    In this programming tutorial, we learned how to find the quotient and remainder of two numbers in C, C++, and Python. To find the quotient of two numbers we simply divide them and to find the reminder we have a modulo operator in every programming language .

    People are also reading:

    Leave a Comment on this Post

    0 Comments