数学相关C++
Math related C++
本文关键字:C++ 更新时间:2023-10-16
#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;
}
给出错误
10|error: invalid operands of types 'float' and 'double(double, double)' to binary 'operator*'|
10|error: expected ';' before 'of'|
有人可以指出错误吗?
你只能在整数类型(char
、short
、int
、long
等)上使用取模运算符%
。
另外,您可能希望将printf("b, c")
更改为 printf("%d, %f",b,c)
。
模运算符不对浮点数进行操作
如果你想找出两个浮点数的模,那么使用fmod(real_number,real_number);
例:-
fmod(5.5,1.3);
输出 : 0.300000
相关文章:
- 没有找到相关文章