是否可以使用C ??中的函数计算比率?或者我必须做一个公式??
答案 0 :(得分:2)
float ratio (float a, float b){
return a/b;
}
您可能遇到以下问题:
int a=5;
int b=4;
float ratio=b/a; // yields 1.0000 since it is interpreted as integer division
float ratioCorrect=(float)b/a; // yields 1.25 because yuo told the compiler to interpret numbers as floats