一、刷题内容
蓝桥杯真题:《成绩统计》
二、知识点
复习:
四舍五入:使用math库中的round()函数,包含头文件math.h
浮点类型输出格式:%.0f表示保留整数部分既保留0位小数
百分号打印:应该使用%%打印百分号更严谨
三、解题代码
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
float a,m,n,pass=0,excellent=0;
cin>>n;
m=n;
while(n!=0)
{
cin>>a;
n--;
if(a>=60) pass++;
if(a>=85) excellent++;
}
printf("%.0f%%\n%.0f%%",round(pass/m*100),round(excellent/m*100));
return 0;
}