[英]Math related C++
#include <stdio.h>
int main(){
float a;
printf("Enter Real Number: ");
scanf("%f", &a);
int b;
b=a*0.393701/12;
float c;
c=a*0.393701%12;
printf("b, c");
return 0;
}
Gives the error 给出错误
10|error: invalid operands of types 'float' and 'double(double, double)' to binary 'operator*'|
10|error: expected ';' before 'of'|
Can someone point out the error please? 有人可以指出错误吗?
You can use the modulo operator %
only on integer types ( char
, short
, int
, long
, etc). 您只能在整数类型( char
, short
, int
, long
等)上使用模运算符%
。
Also, you probably want to change printf("b, c")
to printf("%d, %f",b,c)
. 另外,您可能希望将printf("b, c")
更改为printf("%d, %f",b,c)
。
模运算符不对浮点运算
If you want to find out modulo of two floating point numbers then use fmod(real_number,real_number);
如果要找出两个浮点数的模,则使用fmod(real_number,real_number);
example:- 例:-
fmod(5.5,1.3);
output : 0.300000 产量:0.300000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.