Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- double Member(int n, double x) {
- double res = 1.0;
- for (double i = 1.0; i <= n; i++)
- res *= x / i;
- return res;
- }
- double sin_hy(int n, double x) {
- double sinx = 0.0;
- for (int j = 0; j <= n; j++) {
- double tmp = Member(2 * j + 1, x);
- if (j % 2) {
- tmp = -tmp;
- }
- sinx += tmp;
- }
- return sinx;
- }
- int main(int argc, char** argv) {
- double x = atof(argv[1]);
- int n = atoi(argv[2]);
- struct timespec start, end;
- clock_gettime(CLOCK_MONOTONIC, &start);
- printf("%.10lf\n", sin_hy(n, x));
- clock_gettime(CLOCK_MONOTONIC, &end);
- printf("Time taken: %lf sec.\n", end.tv_sec - start.tv_sec
- + 0.000000001 * (end.tv_nsec - start.tv_nsec));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement