此题考查的对语言四舍五入的理解使用
Code 1#includeCode 2using namespace std; int main() { int n; cin>>n; int greatCount = 0; int goodCount = 0; int i = 0; while(i >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#include using namespace std; int main() { int n; cin>>n; int greatCount = 0; int goodCount = 0; int i = 0; while(i >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; }



