安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

用c++编写以下题目代码输入n个整数输出大于等于平均数的整数输入第一行为输入数据数量nn1第二行为以空格隔开的n个整数输出大于等于平均数的数以空格隔开样例输入44 6 8 9样例输出8 9

  • 日期: 2027-01-21
  • 标签: 常规

#include #include

using namespace std;

int main() { int n; cin >> n;

vector<int> nums(n);
int sum = 0;
for (int i = 0; i < n; i++) {
    cin >> nums[i];
    sum += nums[i];
}

int avg = sum / n;
for (int i = 0; i < n; i++) {
    if (nums[i] >= avg) {
        cout << nums[i] << " ";
    }
}

return 0;

}

用c++编写以下题目代码输入n个整数输出大于等于平均数的整数输入第一行为输入数据数量nn1第二行为以空格隔开的n个整数输出大于等于平均数的数以空格隔开样例输入44 6 8 9样例输出8 9

原文地址: http://www.cveoy.top/t/topic/iZU6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: 通过在中国工商银行公司金融部实习对专业实践技能、职业素质等方面有哪些提高
  • 下一篇: Regarding the punishment of the vessel Tuju Arrow for illegal discharge by the Maritime Bureau we immediately contacted the captain and agent upon receiving the commission and learned that the Ma

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2