我想检查运算if符/是否没有余数:
int x = 0;    
if (x = 16 / 4), if there is no remainder: 
   then  x = x - 1;
if (x = 16 / 5), if remainder is not zero:
   then  x = x + 1;
如何检查是否有余数C?以及
如何实施?
我想检查运算if符/是否没有余数:
int x = 0;    
if (x = 16 / 4), if there is no remainder: 
   then  x = x - 1;
if (x = 16 / 5), if remainder is not zero:
   then  x = x + 1;
如何检查是否有余数C?以及
如何实施?
首先,您需要%余数运算符:
if (x = 16 % 4){
     printf("remainder in X");
}
注意:它不适用于 float/double,在这种情况下,您需要使用fmod (double numer, double denom);.
其次,按照您的意愿实施它:
if (x = 16 / 4), 如果没有余数, x = x - 1;  If (x = 16 / 5), 那么x = x + 1;使用逗号,运算符,您可以按如下方式一步完成(阅读评论):  
int main(){
  int x = 0,   // Quotient.
      n = 16,  // Numerator
      d = 4;   // Denominator
               // Remainder is not saved
  if(x = n / d, n % d) // == x = n / d; if(n % d)
    printf("Remainder not zero, x + 1 = %d", (x + 1));
  else
    printf("Remainder is zero,  x - 1 = %d", (x - 1));
  return 1;
} 
检查工作代码@codepade: first , second , third。
请注意,在 if 条件中,我使用的是 Comma Operator: ,,以了解,operator read: comma operator with an example。
使用 % 运算符查找除法的余数
if (number % divisor == 0)
{
//code for perfect divisor
}
else
{
//the number doesn't divide perfectly by divisor
}
    如果您想找到整数除法的余数,则可以使用模数(%):
if( 16 % 4 == 0 )
{
   x = x - 1 ;
}
else
{
   x = x +1 ;
}
    为此目的使用模运算符。
if(x%y == 0)那么就没有余数了。
在除法运算中,如果结果为浮点数,则只返回整数部分,舍去小数部分。
您可以使用处理余数的模运算符。
模运算符(由 C 中的 % 符号表示)计算余数。所以:
x = 16 % 4;
x 将为 0。
X = 16 % 5;
x 将是 1