Advertisement
SteelK

Untitled

Jun 2nd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include "time.h"
  4. #include <cmath>
  5. #define SIZE 1024
  6.  
  7. using namespace std;
  8.  
  9. void start_for(long double **mas, long double *func);
  10. void work_func(size_t t, size_t s, long double *in_func, long double **mas);
  11. long double formul(size_t t, size_t s);
  12.  
  13. int main()
  14. {
  15.     long double **mas = new long double *[SIZE];
  16.     for (size_t y = 0; y < SIZE; y++)
  17.         mas[y] = new long double[SIZE];
  18.  
  19.     setlocale(0, "");
  20.     srand(time(NULL));
  21.     long double func = 0, sum = 0;
  22.     long double start_time = clock();
  23.     for (size_t i = 0; i < 10000; i++)
  24.     {
  25.         start_for(mas, &func);
  26.         sum = sum + func;
  27.     }
  28.     long double end_time = clock();
  29.     long double time = (1.0 * (end_time - start_time) / CLOCKS_PER_SEC) / 10000;
  30.  
  31.     cout << "Среднее время работы функции = " << time << endl;
  32.     cout << "Сумма работы функции = " << sum << endl;
  33.  
  34.     for (size_t y = 0; y < SIZE; y++)
  35.         delete[] mas[y];
  36.     delete[] mas;
  37.  
  38.     return 0;
  39. }
  40.  
  41.  
  42. void start_for(long double **mas, long double *func)
  43. {
  44.     work_func(rand() % 51, rand() % 51, func, mas);
  45. }
  46.  
  47.  
  48. void work_func(size_t t, size_t s, long double *in_func, long double **mas)
  49. {
  50.     if (!mas[t][s])
  51.     {
  52.         *in_func = formul(t, s);
  53.         mas[t][s] = *in_func;
  54.     }
  55.     else
  56.         *in_func = mas[t][s];
  57. }
  58.  
  59. long double formul(size_t t, size_t s)
  60. {
  61.     return (1.0 * t / s) * log(1 + powl((t + s), 5)) * cosl(powl((t + s), 2));
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement