문제
다음 C 코드의 실행 결과를 쓰시오.
C#include <stdio.h> int main() { int total = 0; for (int j = 2; j <= 6; j++) { if (j % 3 == 0) total += j; } printf("%d", total); return 0; }
정답
9
9
해설
2부터 6까지의 수 중에서 3의 배수를 찾아 더합니다. 2(3의 배수 아님), 3(3의 배수), 4(3의 배수 아님), 5(3의 배수 아님), 6(3의 배수)이므로 3 + 6 = 9입니다.