midterm-2-practice-tas-solutions

midterm-2-practice-tas-solutions - CSE 114 Practice Midterm...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 114 Practice Midterm Exam 2 Thursday, October 21, 2004 NAME (please print legibly): Your University ID Number: NO BS bonus: If you do not know the answer to a problem and leave it blank you will receive 1 point for each sub-part (e.g., a,b,c, etc.) that you leave blank. If you write anything in the space and it is wrong, you will receive a zero. Thus, the score for a completely blank exam is 12. You will not lose any points for small coding details such as misspelling a method name, leaving out some default method arguments, or getting the order of method arguments wrong. QUESTION VALUE SCORE 1 10 2 25 3 15 4 10 5 20 6 15 TOTAL 95 1 1. (10 points) Write a recursive method sum() that computes the sum of the numbers from 1 to n using the following recursive definition: the sum of 1 to n is equal to the sum of 1 to ( n /2) plus the sum of ( n /2 + 1) to n. public int sum (int a, int n) { if (a == n) return a; else { n2 = n / 2; if (n2 < a) n2 = a; return sum(a, n2) + sum(n2+1, n); } } 2 2. (25 points)2....
View Full Document

This note was uploaded on 03/24/2009 for the course CSE 114 taught by Professor Tashbook during the Spring '08 term at SUNY Stony Brook.

Page1 / 7

midterm-2-practice-tas-solutions - CSE 114 Practice Midterm...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online