Олимпиадный тренинг

Задача . 36017


Задача

Темы:
Consider the method reverse:
/** Precondition: n > 0.
* Postcondition:
* - Returns n with its digits reversed.
* - Example: If n = 234, method reverse returns 432.
* @param n a positive integer
* @return n with its digits reversed
*/
int reverse(int n)
{
int rem, revNum = 0;
/* code segment */
return revNum;
}
Which of the following replacements for /* code segment */ would cause the
method to work as intended?
I for (int i = 0; i <= n; i++)
{
rem = n % 10;
revNum = revNum * 10 + rem;
n /= 10;
}
II while (n != 0)
{
rem = n % 10;
revNum = revNum * 10 + rem;
n /= 10;
}
III for (int i = n; i != 0; i /= 10)
{
rem = i % 10;
revNum = revNum * 10 + rem;
}
(A) I only
(B) II only
(C) I and II only
(D) II and III only
(E) I and III only

time 1000 ms
memory 32 Mb
Правила оформления программ и список ошибок при автоматической проверке задач

Статистика успешных решений по компиляторам
Комментарий учителя