C Program to find Quotient and Remainder

CodingTute

Updated on:

C Program to Find Quotient and Remainder

In this example, you will learn how to find Quotient and Remainder by taking dividend and divisor input from the user.

C Program to find Quotient and Remainder

#include <stdio.h>
int main() {
    int divdend , divisor, quotient, rem;
    printf("Enter Dividend: \n");
    scanf("%d", &divdend );
    printf("Enter Divisor: \n");
    scanf("%d", &divisor);

    // Quotient
    quotient = divdend / divisor;

    // Remainder
    rem = divdend % divisor;

    printf("Quotient : %d\n", quotient);
    printf("Remainder : %d", rem);
    return 0;
}
Run Code on Online C Compiler

Output:

Enter Dividend: 7
Enter Divisor: 3
Quotient : 2
Remainder : 1

Explanation:

This C program prompts the user to enter two integers, divdend and divisor, reads them using scanf(), calculates their quotient and remainder using the division and modulo operator respectively, and then displays the quotient and remainder using printf().

After declaring the variables divdend, divisor, quotient, and rem as integers, the program prompts the user to input the values of dividend and divisor using printf() and scanf(), respectively.

Next, the program calculates the quotient and remainder of the two integers using the division and modulo operator, respectively. The quotient is calculated by dividing divdend by divisor, while the remainder is calculated by taking the modulus of divdend with divisor.

Mathematically, we can get the quotient by dividing the divdend with the divisor.

quotient = divdend / divisor;

The remainder can be calculated by performing a modulo operation (%) between the divdend and divisor.

rem = divdend % divisor;

Finally, the program displays the values of quotient and remainder using printf(). It uses the format specifier %d to display the integer value of quotient and remainder.

Follow us on Facebook, YouTube, Instagram, and Twitter for more exciting content and the latest updates.

Exit mobile version