Notice
Recent Posts
Recent Comments
Link
«   2026/02   »
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
Archives
Today
Total
관리 메뉴

행복한 개구리

C++ Tutorial - Math 본문

C++/공부내용

C++ Tutorial - Math

HappyFrog 2022. 6. 14. 16:28

 

 

 


C++ 수학

C++는 당신이 수에 관련된 수학적 업무를 실행할 수 있게 해주는 많은 함수들이 있습니다.

 

 

 


최대값과 최소값

 max(x, y) 함수는 x와 y 중 최대값을 찾는데 사용됩니다.

 

 

예시

#include <iostream>

using namespace std;

int main() {
	cout << max(5, 10);
}

 

그리고  min(x, y)  함수는 x와 y 중 최소값을 찾는데 사용됩니다.

 

 

예시

#include <iostream>

using namespace std;

int main() {
	cout << min(5, 10);
}

 

 

 


C++ <cmath> 헤더

 sqrt (square root, 제곱근),  round (rounds a number, 반올림) 그리고  log (자연로그)와 같은 다른 함수들은  <cmath>  헤더파일에서 찾을 수 있습니다.

 

 

예시

#include <cmath>
#include <iostream>

using namespace std;

int main() {
	cout << sqrt(64) << "\n";
	cout << round(2.6) << "\n";
	cout << log(2);
}

 

 

 


다른 수학 함수들

다른 자주 쓰이는 수학 함수들(<cmath> 라이브러리에 있는)은 아래 목록에서 확인할 수 있습니다.