繁体   English   中英

数学相关的C ++

[英]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;
}

给出错误

10|error: invalid operands of types 'float' and 'double(double, double)' to binary 'operator*'|
10|error: expected ';' before 'of'|

有人可以指出错误吗?

您只能在整数类型( charshortintlong等)上使用模运算符%

另外,您可能希望将printf("b, c")更改为printf("%d, %f",b,c)

模运算符不对浮点运算

如果要找出两个浮点数的模,则使用fmod(real_number,real_number);

例:-

fmod(5.5,1.3);

产量:0.300000

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM