Liamcoder


私信TA

用户名:18817572995

访问量:9554

签 名:

Where there is a will, there is a way.

等  级
排  名 1811
经  验 2484
参赛次数 2
文章发表 11
年  龄 0
在职情况 学生
学  校 上海师范大学
专  业 计算机科学与技术

  自我简介:

屌丝程序狗

解题思路:输入的十个数,用数组来存储。然后定义一个count计数器,作为大于平均数的计数使用。在for循环中每次输入之后都可以将值加和起来,最后求平均值。





注意事项:这种程序用C++会让代码更加简洁。





参考代码:

#include<iostream>

using namespace std;

int main(){

int arg = 0;

int x[10];

int count = 0;

for(int i=0; i<10; i++){

cin >> x[i];

arg += x[i];

}

arg /= 10;

for(int i=0; i<10; i++){

if(x[i]>arg) count++;

}

cout << count;

return 0;

}


 

0.0分

3 人评分

  评论区