Tag: 百分比

C如何计算没有浮点精度的百分比(perthousands)

如何计算从2个int值到表示百分比的int值的百分比(为了更准确度,数百个)? 背景/目的:使用没有FPU的处理器,浮点计算需要花费100倍的时间。 int x = 25; int y = 75; int resultPercentage; // desire is 250 which would mean 25.0 percent resultPercentage = (x/(x+y))*1000; // used 1000 instead of 100 for accuracy printf(“Result= “); printf(resultPercentage); 输出: 结果= 0 当我真正需要的是250.我不能使用任何浮点计算。 正常fpu计算的示例: int x = 25; int y = 75; int resultPercentage; // desire is 250 which […]

如何在c 中打印百分号(%)

我是C的初学者,我想知道为什么这个程序不打印%符号? 代码是: #include main() { printf(“%”); getch(); }