p52 N267 - increment
자연수에 1을 이진수로 더하는 알고리즘(재귀호출식)
function(y)
comment Return + 1;
- if y = 0 then return(1) else
- if y mod 2 = 1 then
- return(2 · increment(⎣y/2⎦))
- else return(y + 1)
Source Code
- int increment(int y)
- {
- if ( y == 0 )
- return 1;
- else
- {
- if ( (y % 2) == 1 )
- return 2 * increment(y/2);
- else
- return y + 1;
- }
- }




최근 덧글