※<cstdlib>
abort() : 프로그램을 "비정상적으로 종료"
exit(n) : 값을 n으로 프로그램을 종료 (n==0이면 성공적인 종료)
d=rand() : d는 [0 : RAND_MAX] 범위에 있는 의사 난수다.
※<cmath>
§ x의 y승을 구하려면 원래는 다음과 같이 구현해야한다.
#include <iostream>
using namespace std;
int main(){
int x, y; cin >> x >> y;
int result = 1;
for (int i = 0; i < y; i++)
result *= x;
cout << result;
}
§ 하지만 <cmath>의 내장함수인 exp2나 pow함수를 이용하면 매우 짧은 코드로 답을 낼 수 있어 유용하다.
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int x, y; cin >> x >> y;
cout << pow(x,y);
}
#include <iostream>
#include <cmath>
using namespace std;
int main(){ // x값 2 한정
int y; cin >> y;
cout << exp2(y);
}
'Algorithms > Algorithm skill' 카테고리의 다른 글
[Math Algorithm특강_Middle]_ 유클리드 호제법, 등수구하기, 방향탐색(knight), 이차원배열의 부분합(포함배제원리) (0) | 2022.11.10 |
---|---|
[Math Algorithm특강_Basic]_약수,배수, 최빈, 회문, 부분합, 일정구간 연속값찾기, 에라토스테네스의 체 (0) | 2022.11.07 |
this.algorithm(4). 중복된 원소제거, unique() ★★★ (0) | 2022.11.03 |
this.algorithm(3). C++ 코테에서 시간초과에 잘 안걸리는 함수 (0) | 2022.11.03 |
this.algorithm(2). merge() 함수, copy() max(), min() 함수 ★★★★★ (0) | 2022.11.02 |