C++ 수학


C++ 수학

C++에는 숫자에 대한 수학적 작업을 수행할 수 있는 많은 기능이 있습니다.


최대 및 최소

함수는 xy 의 가장 높은 값을 찾는 데 사용할 수 있습니다 .max(x,y)

예시

cout << max(5, 10);

그리고 이 함수는 xy 의 가장 낮은 값을 찾는 데 사용할 수 있습니다 .min(x,y)

예시

cout << min(5, 10);

C++ <cmath> 헤더

sqrt(제곱근), round(숫자 반올림) 및 log (자연 로그) 와 같은 다른 함수 는 <cmath>헤더 파일에서 찾을 수 있습니다.

예시

// Include the cmath library
#include <cmath>

cout << sqrt(64);
cout << round(2.6);
cout << log(2);

기타 수학 함수

다른 인기 있는 수학 함수 목록( <cmath>라이브러리에서)은 아래 표에서 찾을 수 있습니다.

Function Description
abs(x) Returns the absolute value of x
acos(x) Returns the arccosine of x
asin(x) Returns the arcsine of x
atan(x) Returns the arctangent of x
cbrt(x) Returns the cube root of x
ceil(x) Returns the value of x rounded up to its nearest integer
cos(x) Returns the cosine of x
cosh(x) Returns the hyperbolic cosine of x
exp(x) Returns the value of Ex
expm1(x) Returns ex -1
fabs(x) Returns the absolute value of a floating x
fdim(x, y) Returns the positive difference between x and y
floor(x) Returns the value of x rounded down to its nearest integer
hypot(x, y) Returns sqrt(x2 +y2) without intermediate overflow or underflow
fma(x, y, z) Returns x*y+z without losing precision
fmax(x, y) Returns the highest value of a floating x and y
fmin(x, y) Returns the lowest value of a floating x and y
fmod(x, y) Returns the floating point remainder of x/y
pow(x, y) Returns the value of x to the power of y
sin(x) Returns the sine of x (x is in radians)
sinh(x) Returns the hyperbolic sine of a double value
tan(x) Returns the tangent of an angle
tanh(x) Returns the hyperbolic tangent of a double value

C++ 연습

연습으로 자신을 테스트하십시오

연습:

x의 가장 높은 값을 인쇄하려면 올바른 함수를 사용하십시오 y.

int x = 5;
int y = 10;
cout << (x, y);