百分比表示百分数,即百分之几的比例。百分比的符号是%。 我们通常计算得到的标记的百分比,投资回报率等。百分比也可以超过100%
。
例如 - 假设有全部(total)和部分(part),可以说部分(part)是全部(total)的百分之多少,计算公式为 -
percentage = ( part / total ) × 100
代码实现
该算法的实现程序如下 -
#include <stdio.h>
int main() {
float percentage;
int total_marks = 1200;
int scored = 1122;
percentage = (float)scored / total_marks * 100.0;
printf("Percentage = %.2f%%", percentage);
return 0;
}
执行上面示例代码,得到以下结果 -
Percentage = 93.50%