C 语言百分比计算程序
百分比表示百分数(百位数),即 100 中各部分的比例。百分比的符号是 %。我们通常计算获得的分数百分比、投资回报率等。百分比也可以超过 100%。
例如 − 假设我们有 total 和 part。所以我们说 part 是 total 的百分之几,应该计算为 −
百分比 = ( part / total ) × 100
算法
查找百分比的算法如下 −
开始
步骤 1 → 收集 部分 和 总计 的值
步骤 2 → 应用公式 { percentage = ( part / total ) × 100 }
步骤 3 → 显示百分比
停止
伪代码
算法的伪代码可以写成 −
procedure percentage() VAR value, total percentage = value / total * 100 RETURN percentage end procedure
实现
该算法的实现如下 −
#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%
mathematical_programs_in_c.html

