此題考查的對語言四舍五入的理解使用
#include<iostream>
using namespace std;int main()
{int n;cin>>n;int greatCount = 0;int goodCount = 0;int i = 0;while(i<n){int grade;cin>>grade;if(grade>=60) goodCount++;if(grade>=85) greatCount++;i++;}float good = 100.0*goodCount/n;float great = 100.0*greatCount/n;printf("%.0f%\n",good);printf("%.0f%\n",great);return 0;
}
round()
四舍五入函數
#include<iostream>
#include<cmath>
using namespace std;int main()
{int n;cin>>n;int greatCount = 0;int goodCount = 0;int i = 0;while(i<n){int grade;cin>>grade;if(grade>=60) goodCount++;if(grade>=85) greatCount++;i++;}cout << round(100.0 * goodCount / n) << "%" << endl;cout << round(100.0 * greatCount / n) << "%" << endl;return 0;
}
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态