fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <cstring>
  6. #include <cmath>
  7. //using namespace std;
  8.  
  9. const int n = 6, m = 4;
  10.  
  11. // строит матрицу с элементами из множества { a,...,b}
  12. // параметр 1 - а
  13. // параметр 2 - b
  14. // параметр 3 - x[m][n]
  15. // параметр 4 - xRow
  16. // параметр 5 - xColumn
  17. void BuildMatrix(double , double , double x[n][m], int);
  18.  
  19. // выводит матрицу на экран}
  20. // параметр 1 - имя матрицы (строка)
  21. // параметр 2 - x[m][n]
  22. // параметр 3 - xRow
  23. // параметр 4 - xColumn
  24. void PrintMatrix(std:: string , double x[n][m], int ,int);
  25.  
  26. // считает сумму площадей
  27. // параметр 1 - а
  28. // параметр 2 - b
  29. // параметр 3 - x[m][n]
  30. // параметр 4 - n
  31. // параметр 5 - sum
  32. double suma(double, double, double x[n][m], int, double);
  33. int main()
  34. {
  35. double k[n][m];
  36. double a = 3, b = 15;
  37. BuildMatrix(a, b, k, n);
  38. PrintMatrix("A", k, n, m);
  39. double Sum;
  40. Sum = suma(a, b, k, n, Sum);
  41. std::cout << "Сумма равна = " << Sum;
  42. return 0;
  43. }
  44.  
  45. // строит матрицу с элементами из множества { a,...,b}
  46. void BuildMatrix(double a, double b, double x[n][m], int count)
  47. {
  48. double Deltax = (b - a) / (count - 1);
  49. for(int i = 0; i < count; i++)
  50. {
  51. x[i][0] = a + i * Deltax;
  52. x[i][1] = pow(3,2*x[i][0]);
  53. }
  54. for(int l = 1; l < count; l++)
  55. {
  56. x[l][2] = (x[l][1] - x[l-1][1]) / (x[l][0] - x[l-1][0]);
  57. }
  58. for(int r = 0; r < count-1; r++)
  59. {
  60. x[r][3] = (x[r+1][1] - x[r][1]) / (x[r+1][0] - x[r][0]);
  61. }
  62. }
  63.  
  64. // выводит матрицу на экран с элементами из множества { a,...,b}
  65. void PrintMatrix(std:: string matrixName, double x[n][m], int xRow, int xColumn)
  66. {
  67. std:: cout << matrixName + "= [\n";
  68. for (int i = 0; i < xRow; i++)
  69. {
  70. for(int j = 0; j < xColumn; j++)
  71. std::cout << std::setw(15) << x[i][j];
  72. std::cout << "\n";
  73. }
  74. std::cout << " ]\n" ;
  75. }
  76.  
  77. // считает сумму площадей
  78. double suma(double a, double b, double x[n][m], int n, double sum)
  79. {
  80. double s, Deltax;
  81. Deltax = (b - a) / (n - 1);
  82. for(int i = 0; i < (n - 1); i++)
  83. s += ((x[i][1] + x[i+1][1]) / 2) * Deltax;
  84. sum = s;
  85. return sum;
  86. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
A= [
              3            729   2.35427e-310        58947.6
            5.4         142203        58947.6    1.14987e+07
            7.8     2.7739e+07    1.14987e+07      2.243e+09
           10.2    5.41095e+09      2.243e+09    4.37534e+11
           12.6    1.05549e+12    4.37534e+11    8.53482e+13
             15    2.05891e+14    8.53482e+13   2.35427e-310
 ]
Сумма равна = 2.49616e+14