※<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);
}

+ Recent posts