Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <fstream>
- #include <iostream>
- using namespace std;
- void fill_in(int* a, const int N, ifstream& file)
- {
- for (int i = 0; i < N; i++)
- {
- file >> a[i];
- cout << "Q[" << i << "] = " << a[i] << endl;
- }
- }
- double sr_arifm_ch(int* a, const int N)
- {
- int k_ch = 0; double summ_ch = 0;
- for (int i = 0; i < N; i++)
- {
- if (a[i] % 2 == 0)
- {
- summ_ch += a[i];
- k_ch++;
- }
- }
- return summ_ch / k_ch;
- }
- int main()
- {
- setlocale(0, "Rus");
- ifstream file("J:\\Универ\\Программирование\\Практика_txt\\z_10.txt");
- if (file.is_open())
- {
- const int N = 33;
- int Q[N];
- int k_ch = 0; double summ_ch = 0;
- cout << "Массив Q: " << endl;
- fill_in(Q, N, file);
- cout << "Среднее арифметическое: " << sr_arifm_ch(Q, N) << endl;
- system("pause");
- return 0;
- }
- else
- {
- cout << "Файл не открыт" << endl;
- system("pause");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement