Programming

Just another WordPress.com weblog

ข้อสอบ CT212 finale ข้อย่อย Recursive ปี 2551

แสดงความเห็นโดย จั่น บน ธันวาคม 5, 2008

จงแปลง function นี้ให้เป็น Recursive

double test(int a, int b){

double sum = 1.0;

for(int i=0; i<b; i++){

sum = sum * (1/a);

}

}

แปลงเป็น Recursive function ได้เป็น

double test(int a, int b){

if(b == 0){

return 1.0;

} else{

return (1.0/a) * test(a, b-1);

}

}

ใส่ความเห็น

XHTML: คุณสามารถใช้แท็กเหล่านี้ได้: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>