250x250
반응형
Notice
Recent Posts
Recent Comments
Link
목록반복문 (1)
N

우선 tmp 변수를 선언하여 x를 대입한다. tmp는 계속해서 똑같은 값(x)을 더해줄 때 사용한다. 왜냐하면 for문에서 x의 값을 넣었을 때, x += x를 하면 x = 2일 때, x = 2, 4, 8, 16... 이 되기 때문이다..! 그래서 변하지 않는 tmp를 이용하여 x에 더해준다..! #include #include using namespace std; vector solution(int x, int n) { vector answer; int tmp = x; for(int i = 0; i < n; i++) { answer.push_back(x); x += tmp; } return answer; }
프로그래머스 알고리즘/1단계
2020. 4. 29. 11:10