下面是我的代码:
#include <stdio.h>
int main ( )
{
float a = 5,b = 2;
int c,d;
c = a % b;
d = a/2;
printf("%d\n",d);
return 0;
}
当我尝试编译它时,我得到了
"Invalid operands to binary %"
在第 6 行。我该如何解决这个问题?
最佳答案
c = a % b;
您不能将 float
用作 %
运算符的操作数。
改用 math.h
中的 fmod
。
double a=5,b=2,c;
c=fmod(a,b); // it returns double
关于c - 二进制 % 的无效操作数(有 float 和 float ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758350/