qfedu-basic-level/day8/homework/h1.cpp

23 lines
447 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 输入一个整数 n然后输入 n 个整数,输出它们的平均值。
#include <iostream>
using namespace std;
int main()
{
int n, sum = 0;
int nums[100];
cout << "请输入整数 n: ";
cin >> n;
int n_copy = n;
cout << "请输入 " << n << " 个整数: ";
while (--n >= 0)
{
cin >> nums[n];
sum += nums[n];
}
cout << "平均值为:" << sum / n_copy << endl;
return 0;
}