Ghytro

shit.c

Mar 2nd, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7.     clock_t start_time = clock();
  8.     for (int N = 2e7; N <= 2e8; N += 2e7)
  9.     {
  10.         double sum = 0,
  11.         sum_cor = 0,
  12.         cor = 0;
  13.         for (double n = 1; n <= N; ++n)
  14.         {
  15.             double f = sqrt((7 + 3*n) / (5 + n));
  16.             double fcor = f - cor;
  17.             //сумма с коррекцией
  18.             double temp_sum = sum_cor;
  19.             sum_cor += fcor;
  20.             cor = (sum_cor - temp_sum) - fcor;
  21.  
  22.             //простая сумма
  23.             sum += f;
  24.         }
  25.         printf("%9d%18.4f%18.4f%10.4f\n", N, sum, sum_cor, sum - sum_cor);
  26.     }
  27.     clock_t end_time = clock();
  28.     double execution_time = (end_time - start_time) / (double)CLK_TCK;
  29.     printf("Time of execution: %lfs", execution_time);
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment