C언어/C언어 예제

[math.h] cos, cosf, cosl 함수 예제 코드, cosine 계산

언제나휴일 2016. 5. 8. 10:07
반응형

[math.h] cos, cosf, cosl 함수 예제 코드, cosine 계산


//C언어 표준 라이브러리 함수 가이드

//double cos(double x); cosine 계산

//float cosf(float x); cosine 계산

//long double cosl(long double x); cosine 계산

//0, 30, 45, 60, 90도의 cosine

 

#include <math.h>

#include <stdio.h>

 

int main(void)

{

    double radian;

    radian = 0.0;

    printf("%f \n", radian * 180 / 3.141592);

    printf("cos(%f)  = %.30f\n", radian, cos(radian));

    printf("cosf(%f) = %.30f\n", radian, cosf((float)radian));

    printf("cosl(%f) = %.30f\n", radian, cosl(radian));

 

    radian = 30 * 3.141592 / 180;

    printf("%f \n", radian * 180 / 3.141592);

    printf("cos(%f)  = %.30f\n", radian, cos(radian));

    printf("cosf(%f) = %.30f\n", radian, cosf((float)radian));

    printf("cosl(%f) = %.30f\n", radian, cosl(radian));

 

    radian = 45 * 3.141592 / 180;

    printf("%f \n", radian * 180 / 3.141592);

    printf("cos(%f)  = %.30f\n", radian, cos(radian));

    printf("cosf(%f) = %.30f\n", radian, cosf((float)radian));

    printf("cosl(%f) = %.30f\n", radian, cosl(radian));

 

    radian = 60 * 3.141592 / 180;

    printf("%f \n", radian * 180 / 3.141592);

    printf("cos(%f)  = %.30f\n", radian, cos(radian));

    printf("cosf(%f) = %.30f\n", radian, cosf((float)radian));

    printf("cosl(%f) = %.30f\n", radian, cosl(radian));

 

    radian = 90 * 3.141592 / 180;

    printf("%f \n", radian * 180 / 3.141592);

    printf("cos(%f)  = %.30f\n", radian, cos(radian));

    printf("cosf(%f) = %.30f\n", radian, cosf((float)radian));

    printf("cosl(%f) = %.30f\n", radian, cosl(radian));

 

    return 0;

}

}

 

출력

0.000000

cos(0.000000)  = 1.000000000000000000000000000000

cosf(0.000000) = 1.000000000000000000000000000000

cosl(0.000000) = 1.000000000000000000000000000000

30.000000

cos(0.523599)  = 0.866025458250249569047696240887

cosf(0.523599) = 0.866025447845458984375000000000

cosl(0.523599) = 0.866025458250249569047696240887

45.000000

cos(0.785398)  = 0.707106896725981814988415408152

cosf(0.785398) = 0.707106888294219970703125000000

cosl(0.785398) = 0.707106896725981814988415408152

60.000000

cos(1.047197)  = 0.500000188675109646929684004135

cosf(1.047197) = 0.500000178813934326171875000000

cosl(1.047197) = 0.500000188675109646929684004135

90.000000

cos(1.570796)  = 0.000000326794896538138350772186

cosf(1.570796) = 0.000000313916473260178463533521

cosl(1.570796) = 0.000000326794896538138350772186


프로그래밍 언어 및 기술 학습, 무료 동영상 강의 언제나 휴일 티스토리

반응형