Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1.  
  2.     #include <stdlib.h>
  3.     #include <stdio.h>
  4.     #include <time.h>
  5.      
  6.     int clock_gettime(clockid_t clk_id, struct timespec *tp);
  7.     int main(int argc, char *argv[]) {
  8.      
  9.     struct timespec {
  10.       time_t   tv_sec;  /* seconds */
  11.       long     tv_nsec;   /* nanoseconds */
  12.     };
  13.  
  14.     struct timespec tps, tpe;
  15.     clock_gettime(CLOCK_REALTIME, &tps);
  16.      
  17.           float xp = 2;
  18.           float xk = 5;
  19.           float calka = 0;
  20.           float dx = 0;
  21.           int i = 0;
  22.           int n = 3;
  23.           dx = (xk - xp) / (float)n;
  24.        
  25.           calka = 0;
  26.           for (i = 1; i < n; i++) {
  27.             calka += (xp + i * dx)*(xp + i * dx);
  28.           }
  29.           calka += ((xp*xp) + (xk*xk)) / 2;
  30.           calka *= dx;
  31.     clock_gettime(CLOCK_REALTIME, &tpe);
  32.     printf("%lu s, %lu ns\n", tpe.tv_sec-tps.tv_sec,
  33.         tpe.tv_nsec-tps.tv_nsec);
  34.           return 0;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement