본문 바로가기
흔한 학교 생활/든든한 C 프로그래밍

[C언어] C 프로그래밍 언어 math.h 헤더 파일 함수 종류 30가지, 간단한 예시 예제

by 흔한 학생 2023. 6. 30.
반응형
#include <stdio.h>
#include <math.h>

int main(void)
{
	//1. sqrt: root 값 계산
	printf("4의 제곱근은 %lf\n", sqrt(4));

	//2. acos: arc cosine 계산
	printf("arccos(-1)은 %lf\n", acos(-1));
	
	//3. asin: arc sine 계산
	printf("arcsin(0)은 %lf\n", asin(0));
	
	//4. atan: arc tangent 계산
	printf("arctan(1)은 %lf\n", atan(1));

	//5. cos: cosine 계산
	printf("cos(0)은 %lf\n", cos(0)); 
	
	//6. sin: sine 계산
	printf("sin(3.14)은 %lf\n", sin(3.14)); 
	
	//7. tan: tangent 계산
	printf("tan(0)는 t%lf\n", tan(0)); 
	
	//8. exp: e의 지수 계산
	printf("e의 1승은 %lf\n", exp(1));
	
	//9. ldexp: x * 2 ^ n 계산
	printf("5x2^3은 %lf\n", ldexp(5, 3)); 
	
	//10. log: log 계산
	printf("log 10은 %lf\n", log(10)); 

	//10. log10: 밑이 10인 log 계산
	printf("log10의 10은 %lf\n", log10(10));

	//11. hypot: 직각 삼각형의 빗변의 길이 계산
	printf("양 변이 1인 직각삼각형의 빗변의 길이는 %lf\n", hypot(1, 1));
	
	//12. pow: 지수 계산
	printf("2의 4승은 %lf\n", pow(2, 4));
	
	//13. ceil: 올림
	printf("2.5를 올림하면 %lf\n", ceil(2.5));
	
	//14. floor: 내림
	printf("2.5를 내림하면 %lf\n", floor(2.5));

	//15. fmod: 나눗셈에서 나머지
	printf("5/3의 나머지는 %lf\n", fmod(5, 3));
	
	//16. cosh: Hyperbolic cosine 함수
	printf("cosh(3)은 %lf\n", cosh(3));
	
	//17. sinh: Hyperbolic sine 함수
	printf("sinh(3)은 %lf\n", sinh(3));

	//18. tanh: Hyperbolic tangent 함수
	printf("tanh(3)은 %lf\n", tanh(3));
	
	//19. exp2: 밑이 2인 지수
	printf("2의 4승은 %lf\n", exp2(4));
	
	//20. log2: 밑이 2인 로그
	printf("log2의 4는 %lf\n", log2(4));

	//21. logb: 밑이 2인 로그에서 정수 부분
	printf("log2의 5에서 정수 부분은 %lf\n", logb(5));
	
	//22. scalbn: x 곱하기 2 ^ n 계산
	printf("3x2^3은 %lf\n", scalbn(3, 3));

	//23. cbrt: 세제곱근
	printf("2의 세제곱은 %lf\n", cbrt(2));

	//24. nearbyint: 가장 가까운 정수
	printf("2.483에서 가장 가까운 정수는 %lf\n", nearbyint(2.483));
	
	//25. round: 반올림
	printf("2.4를 반올림 하면 %lf\n", round(2.4));

	//26. trunc: 소수점 이하 자리 버림
	printf("2.4의 소수점 이하자리를 버리면 %lf\n", trunc(2.4));
	
	//27. fmax 최대값 도출
	printf("4/5와 5/6중 최대값은 %lf\n", fmax((double)4/5, (double)5/6));
	
	//28. fmin: 최소값 도출
	printf("4와 5 중 최소값은 %lf\n", fmin(4, 5));

	//29. abs: 절댓값 계산
	printf("-4의 절댓값은 %d\n", abs(-4));

	//30. fma: (x*y)+z 계산
	printf("(3x4)+1은 %lf\n", fma(3, 4, 1));

	return 0;
}
반응형