How to find the quotient and remainder in C language?
In C language, we can use the division operator “/” to find the quotient, and use the modulus operator “%” to find the remainder.
For example, to find the quotient and remainder of 10 divided by 3, you can use the following code:
#include <stdio.h>
int main() {
int dividend = 10; // 被除数
int divisor = 3; // 除数
int quotient, remainder;
quotient = dividend / divisor; // 求商
remainder = dividend % divisor; // 求余数
printf("商:%d\n", quotient);
printf("余数:%d\n", remainder);
return 0;
}
The outcome of the operation:
商:3
余数:1
In the code above, the dividend is 10, the divisor is 3. The division operator “/” is used to calculate the quotient as 3, and the modulus operator “%” is used to calculate the remainder as 1.