蓝桥杯 ALGO-80 算法训练 整数平均值

版权声明:【https://github.com/liuchuo】大四在校生,水平有限,还望学长们多多包涵,Github真诚求Star~不甚感激!!!(卖萌脸ヾ(=^▽^=)ノ https://blog.csdn.net/liuchuo/article/details/84257819

编写函数,求包含n个元素的整数数组中元素的平均值。要求在函数内部使用指针操纵数组元素,其中n个整数从键盘输入,输出为其平均值。

样例输入: (输入格式说明:5为输入数据的个数,3 4 0 0 2 是以空格隔开的5个整数)
5
3 4 0 0 2
样例输出:
1
样例输入:
7
3 2 7 5 2 9 1
样例输出:
4

#include <iostream>
char c[1000][1000];
using namespace std;
int main() {
    int n, sum = 0, a[1000];
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n; i++)
        sum += *(a+i);
    cout << sum / n;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/liuchuo/article/details/84257819