인텔의 개발자 면접 문제중…

Find three ways to change one character in the following code so that the resulting
code will print exactly 20 minus signs

Remember: for each solution you can only change “one” character from this original code:

[code]int i, n=20;
for(i =0 ; i < n ; i–)
  printf(“-“);[/code]
This is a question asked in an Interview in Intel.

인텔의 개발자 면접에서 나왔던 문제라고 합니다. 기존의 소스에서 한개의 문자만 수정하여 마이너스(-)가 20개 찍히게 하라는 문제인데요. 3가지 답이 있다고 하네요. 답을 아시겠습니까?


[#M_ more.. | less.. |[code]int i, n = 20;
for(i = 0; i < n ; n–)
  printf(“-“);[/code]
n이 1씩 줄어들다가 0이 되면 false가 되어 Loop가 종료됩니다.

[code]int i, n = 20;
for(i = 0 ; -i < n ; i–)
  printf(“-“);[/code]
i값에 음수를 붙여 음수값을 양수로 바꾸어 비교합니다.
i값이 1씩 줄어들다가 -20이 되면 -(-20) < 20이 되어 종료됩니다.

[code]int i, n = 20;
for(i = 0; i + n; i–)
  printf(“-“);[/code]
i값이 1씩 줄어들다가 -20 + 20 = 0 이 되어 false가 되어 Loop가 종료됩니다.
_M#]