Advertisement
jelyslime

qsen

Feb 7th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <cmath>
  4. #include <fstream>
  5.  
  6. void avgFS(double **arr, int first, int sec);
  7. void minmax(double **arr, int sizeOne, int SizeTwo);
  8.  
  9. int main() {
  10. std::ifstream in;
  11. in.open("input_file.txt");
  12.  
  13. double arr[5][5];
  14. double el;
  15.  
  16. if (in.is_open()) {
  17. int M = 0;
  18. int N = 0;
  19. while (in >> el) {
  20. if (N == 5 -1)
  21. {
  22. M++;
  23. }
  24. arr[M][N++] = el;
  25. }
  26. }
  27.  
  28. in.close();
  29. avgFS(arr, 5, 5);
  30. minmax(arr, 5, 5);
  31.  
  32.  
  33. return 0;
  34. }
  35.  
  36. void avgFS(double **arr, int first, int sec)
  37. {
  38. double sum = 0;
  39. int cnt = 0;
  40. for (int i = 0; i < first; i++)
  41. {
  42. for (int j = 0; j < sec; j++) {
  43.  
  44. if (arr[i][j] > (-5) && arr[i][j] < 5)
  45. {
  46. sum = sum + arr[i][j];
  47. cnt++;
  48. }
  49.  
  50. }
  51. }
  52.  
  53. double sumRes = sum / cnt;
  54. std::cout << "Sumata ot vs elementi na masiva v diapazona -5 , 5 e : " << sumRes;
  55.  
  56. }
  57.  
  58. void minmax(double **arr, int sizeOne, int SizeTwo)
  59. {
  60. double tmpMin = 0;
  61. double tmpMax = 0;
  62.  
  63. for (int i = 0; i < sizeOne; i++)
  64. {
  65. for (int j = 0; j < SizeTwo; j++) {
  66.  
  67. if (arr[i][j] < tmpMin)
  68. {
  69. tmpMin = arr[i][j];
  70. }
  71.  
  72. if (arr[i][j] > tmpMax)
  73. {
  74. tmpMax = arr[i][j];
  75. }
  76.  
  77. }
  78. }
  79.  
  80. double minMaxRes = tmpMax / tmpMin;
  81.  
  82. std::cout << "sredno aritmetichno na minimalniq i maksimalniq indeks e : " << minMaxRes;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement