CS1043004b - April 2004 Computer Science Foundation Exam...

This preview shows pages 1–2. Sign up to view the full content.

April 2004 Computer Science Foundation Exam Grading Criteria for CS1 – Part B Problem #1 [12 points total] Must write a recursive function. Many students will attempt this problem and use no recursion at all. Give only 4 points credit if their solution is correct but not recursive. 1. [ 12 points ] The digital root of a number is obtained by summing up the digits repeatedly until only a single digit remains. For example, the digital root of 7854 is obtained by computing 7+8+5+4 which is 24. Next the digits 2 and 4 are summed to yield 6. Since it is a single digit, this forms the digital root of the given number. Write a recursive function root(int n) that returns the digital root of the argument without making use of any loop constructs ( like for, while etc.) in your function. Partial credit may be given in case your function includes such constructs. root(n) if ( n/10) = =0 ) return ( n % 10 ); else return root( n % 10 + root ( n /10 ) ); Grading Policy; Give 12 points if recursive solution is correct Give maximum

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/21/2011.

Page1 / 3

CS1043004b - April 2004 Computer Science Foundation Exam...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online