c语言取整和取余的有哪些方法
在C语言中,取整和取余可使用以下方法:
以下是一些示例:
#include
int main() {
int a = 10;
int b = 3;
int quotient = a / b; // 取整
int remainder = a % b; // 取余
printf("Quotient: %d
", quotient);
printf("Remainder: %d
", remainder);
return 0;
}
输出结果为:
Quotient: 3
Remainder: 1
在这个例子中,a 除以 b 的商为 3,余数为 1。
TOP