Advertisement
jelyslime

ivan

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