Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define N 10
- void init(int a[N]) {
- for (int i = 0; i < N; ++i)
- a[i] = rand() % 10;
- }
- void print(int a[N]) {
- for (int i = 0; i < N; ++i)
- cout << a[i] << " ";
- cout << endl;
- }
- double average(int a[N]) {
- double s = 0;
- int k = 0;
- for (int i = 0; i < N; ++i)
- if (a[i] > 0) {
- s += a[i];
- ++k;
- }
- return s / k;
- }
- int main() {
- setlocale(LC_ALL, "rus");
- int a[N], b[N];
- init(a);
- print(a);
- init(b);
- print(b);
- double x = average(a);
- cout << "Среднее арифметическое массива a: " << x << endl;
- double y = average(b);
- cout << "Среднее арифметическое массива b: " << y << endl;
- cout << "Произведение средних: " << x * y << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement