Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- int clock_gettime(clockid_t clk_id, struct timespec *tp);
- int main(int argc, char *argv[]) {
- struct timespec {
- time_t tv_sec; /* seconds */
- long tv_nsec; /* nanoseconds */
- };
- struct timespec tps, tpe;
- clock_gettime(CLOCK_REALTIME, &tps);
- float xp = 2;
- float xk = 5;
- float calka = 0;
- float dx = 0;
- int i = 0;
- int n = 3;
- dx = (xk - xp) / (float)n;
- calka = 0;
- for (i = 1; i < n; i++) {
- calka += (xp + i * dx)*(xp + i * dx);
- }
- calka += ((xp*xp) + (xk*xk)) / 2;
- calka *= dx;
- clock_gettime(CLOCK_REALTIME, &tpe);
- printf("%lu s, %lu ns\n", tpe.tv_sec-tps.tv_sec,
- tpe.tv_nsec-tps.tv_nsec);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement