Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fstream>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. void fill_in(int* a, const int N, ifstream& file)
  7. {
  8. for (int i = 0; i < N; i++)
  9. {
  10. file >> a[i];
  11. cout << "Q[" << i << "] = " << a[i] << endl;
  12. }
  13. }
  14.  
  15. double sr_arifm_ch(int* a, const int N)
  16. {
  17. int k_ch = 0; double summ_ch = 0;
  18. for (int i = 0; i < N; i++)
  19. {
  20. if (a[i] % 2 == 0)
  21. {
  22. summ_ch += a[i];
  23. k_ch++;
  24. }
  25. }
  26. return summ_ch / k_ch;
  27. }
  28.  
  29. int main()
  30. {
  31. setlocale(0, "Rus");
  32. ifstream file("J:\\Универ\\Программирование\\Практика_txt\\z_10.txt");
  33. if (file.is_open())
  34. {
  35. const int N = 33;
  36. int Q[N];
  37. int k_ch = 0; double summ_ch = 0;
  38. cout << "Массив Q: " << endl;
  39. fill_in(Q, N, file);
  40. cout << "Среднее арифметическое: " << sr_arifm_ch(Q, N) << endl;
  41. system("pause");
  42. return 0;
  43. }
  44. else
  45. {
  46. cout << "Файл не открыт" << endl;
  47. system("pause");
  48. return 0;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement