看了就会的解法:
适合刚入门编程语言的伙伴参考,
本人也是刚刚入门,
刚入门的伙伴可以一起讨论;
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double n, a[10001], count=0,num=0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (a[i] >= 60) {
count++;
}
if (a[i] >= 85) {
num++;
}
}
double s1 = count / n*100.0;
int s11 = round(s1);
double s2 = num / n*100.0;
int s22 = round(s2);
cout << s11 << "%" << endl << s22 << "%";
return 0;
}
我为什么变量都用的double,
因为我懒,
懂得都懂;
欢迎大家提出代码里面的瑕疵,欢迎指错
注意的是里面有一个函数,round()函数
round() 函数:用来作四舍五入的运算
double round (double x);
float round (float x);
long double round (long double x);
double round (T x);
注意:需加头文件“#include<math.h>”
末尾:
欢迎大家看完本篇,感兴趣关注一下后续还会更新适合刚入门的小伙伴参考的代码。
谢谢!