본문 바로가기

자격증

[정보처리기능사] 라이브러리의 활용(math, string)

~ 목차 ~

 

표준 C언어 라이브러리

 

함수 헤더파일 설명
log math.h double log(double a); 로그 계산
log 10 math.h double log10(double a); 밑이 10인 로그
pow math.h double pow(double a, double b); a의 b제곱
sqrt math.h double sqrt(double a); 제곱근 계산(루트)
tan math.h double tan(double a); 탄젠트 
abs stdlib.h int abs(int n); 정수 인수 n의 절대값 계산
atoi stdlib.h int atoi(char str); 문자열을 정수로 변환
malloc stdlib.h void *malloc(size_t size); 동적 메모리 할당
rand stdlib.h int rand(void); 임의의 난수 생성(랜덤숫자)
strcat string.h char *strcat(char *string1, const char *string2); string2를 string1에 연결
strcpy string.h char *strcpy(char *string1, const char *string2); string2를 string1에 복사
strlen string.h size_t strlen(const char *string); string 문자열 길이 계산

 

 

 

javascript(자바스크립트) math객체 사용

 

 

함수 설명 설명
PI 원주율 값 math.PI π값
E 자연 로그 상수 math.E e값( 약 2.718 )
abs() 절대값 math.abs( -5 ) 5
ceil() 올림값 math.ceil( .6 ) 1.0
round() 반올림 math.round( .6 ) 1.0
floor() 내림값 math.floor( .6 ) 0.0
pow( a, b ) a의 b승  math.pow(3, 3) 3의 3승
max() 두 수 중 큰 값 math.max(-5, 10) 10
min() 두 수 중 작은 값을 반환  math.min(-5, 10) -5
random() 0과 1사이의 난수 값을 반환 parseInt(Math.random()*100) 0부터 100사이의 정수값(랜덤)
sqrt() 제곱근을 반환 math.sqrt(3) 루트 3
exp() e의 거듭제곱 math.exp(3) math.E 의 3거듭제곱
sin() 사인 값 math.sin(0) 0
log() 로그 값 Math.log10(x) , Math.log2(x) 밑이 10인 로그, 밑이 2인 로그
    Math.LN2 2의 자연로그( 약 0.693 )
    Math.LN10 10의 자연로그(  약 2.303 )
    Math.LOG2E 밑이 2인 로그 E( 약 1.443 ) 
    Math.LOG10E 밑이 10인 로그 E( 약 0.434)

 

 

 

 

python(파이썬) math모듈 사용

 

 

함수 설명 설명
PI 원주율 값 math.pi π값( 약 3.14 )
E 자연 로그 상수 math.e e값( 약 2.718 )
    math.tau 타우( 약  6.283 )
fabs() 절대값 math.fabs(-3.14) 3.14
ceil() 올림값 math.ceil( .6 ) 1.0
copysign(a, b) 두 번째 인자의 부호만 취해 첫 번째 인자에 적용 math.copysign(3.14, -3) -3.14
factorial() 팩토리얼 함수, 1부터 인자로 주어진 값까지 모두 곱하는 값 math.factorial(5) 120
floor() 내림값 math.floor(-3.14) -4
trunc() 0으로가는 내림 math.trunc(-3.14) -3
frexp(a) a = m * 2**e , m과 e를 반환 math.frexp(100) (0.78125, 7)
ldexp(a) m * 2**e  math.ldexp(0.78125, 7) 100
gcd() 최대공약수 math.gcd(6, 8) 2
modf()
정수와 소수 부분으로 분리 math.modf(3.14) (0.14000000000000012, 3.0)
pow( a, b ) a의 b승  math.pow(3, 2) 9
    math.degrees(x) 라디안으로 표현된 각도를 60분법 각도로 변환
    math.radians(x) 60분법으로 표현된 각도를 라디안 각도로 변환
sqrt() 제곱근을 반환 math.sqrt(25) 5.0
sin() 사인 값 math.sin(0) 0
log(a, b) b를 밑으로 하는 log a에 대한 로그 값 math.log(10, 10) 1
    math.log1p(x) e를 밑으로 하는 x+1로그
    math.log2(x) 2를 밑으로 하는 x로그
    math.log10() 10을 밑으로 하는 x로그

 

728x90