Advertisement
pexea12

Original (a) version

Feb 9th, 2020
1,590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. #define N 10000000
  5.  
  6.  
  7. int main()
  8. {
  9.   double a[N], b[N];
  10.   clock_t start, end;
  11.  
  12.   for (int i = 0; i < N; ++i) b[i] = i;
  13.  
  14.   int i;
  15.  
  16.   start = clock();
  17.   for (i = 0; i < N - 1; ++i) {
  18.     if (i < 500)
  19.       a[i] = 4.0 * b[i] + b[i + 1];
  20.     else
  21.       a[i] = 4.0 * b[i + 1] + b[i];
  22.   }
  23.  
  24.   end = clock();
  25.  
  26.   for (int i = 0; i < 100; ++i) {
  27.     printf("%f\n", a[i]);
  28.   }
  29.  
  30.   double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
  31.   printf("Elapsed time: %f\n", cpu_time_used);
  32.  
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement