C 언어: sin 함수, cos 함수, tan 함수

C언어: 삼각함수


/// 헤더파일

#include <math.h>

/// 함수원형

double sin (double x);
double cos (double x);
double tan (double x);

/// 인자

double x: 실수형 값(호도값)

/// 반환값

성공시 반환값(return value): 계산값

/// 참고파일

헤더파일: math.h(연결)
소스파일: s_sin.c(연결) with cos()
소스파일: s_tan.c(연결)

reference
https://man7.org/linux/man-pages/man3/sin.3.html
https://man7.org/linux/man-pages/man3/cos.3.html
https://man7.org/linux/man-pages/man3/tan.3.html

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <math.h>
 
#define PI  3.14
//#define PI 3.141
//#define PI 3.1415
//#define PI 3.14159
//#define PI 3.141592
//#define PI 3.1415926
//#define PI 3.14159265
//#define PI 3.141592653
//#define PI 3.1415926535
 
void precision(int value, double number); // 사용자 정의 함수로 value정수 크기만큼 소수점의 개수를 조절
 
int main(void) {
    double sine, cosine, tangent;
 
    sine    = sin(PI);
    cosine  = cos(PI);
    tangent = tan(PI);
 
    puts("호도값(라디안)의 경우 반지름이 1인 원에서");
    puts("Sine(0)    =  0,  Cosine(0)   =  1, Tangent(0)    = 0");
    puts("Sine(π/2)  =  1,  Cosine(π/2) =  0, Tangent(π/2)  = ?");
    puts("Sine(π)    =  0,  Cosine(π)   = -1, Tangent(π)    = 0");
    puts("Sine(3π/2) = -1, Cosine(3π/2) =  0, Tangent(3π/2) = ?");
    puts("임을 쉽게 알 수 있습니다.");
    puts("주석의 π(pi)값을 바꾸어 가면서 다음을 확인해 보세요.\n");
 
    for(int i = 2; i < 12; i++) {
        printf("Sine    PI(%lf) = ", PI); /* << */ precision(i, sine);    /* << */ puts("");
        printf("Cosine  PI(%lf) = ", PI); /* << */ precision(i, cosine);  /* << */ puts("");
        printf("Tangent PI(%lf) = ", PI); /* << */ precision(i, tangent); /* << */ puts("\n");
    }    
 
    return 0;
}
 
void precision(int value, double number) {
    switch (value) {
        case  1 : printf("%.1lf",  number);
                  break;
        case  2 : printf("%.2lf",  number);
                  break;
        case  3 : printf("%.3lf",  number);
                  break;
        case  4 : printf("%.4lf",  number);
                  break;
        case  5 : printf("%.5lf",  number);
                  break;
        case  6 : printf("%.6lf",  number);
                  break;
        case  7 : printf("%.7lf",  number);
                  break;
        case  8 : printf("%.8lf",  number);
                  break;
        case  9 : printf("%.9lf",  number);
                  break;
        case 10 : printf("%.10lf", number);
                  break;
        case 11 : printf("%.11lf", number);
                  break;
        default : printf("Limited");
                  break;
    }
}
cs

* 실행환경: Linux(5.7.6-x86_64-linode136)
* 컴파일러: gcc (Ubuntu 6.5.0-2ubuntu1~14.04.1) 6.5.0 20181026


- 당신을 응원합니다. -

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드