Sampleexam1

Sampleexam1 - COP 3502 Computer Science I Exam #1 6/4/08...

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

View Full Document Right Arrow Icon
COP 3502 – Computer Science I Exam #1 – 6/4/08 (Wednesday) Name : ______________________________ 1) (10 pts) Write a recursive function that determines the sum of the digits of its input parameter, n . Fill in the function below. (Hint: sumofdigits(72368) = 8 + sumofdigits(7236).) int sumofdigits(int n) { if (n>0) return n%10 + sumofdigits( n/10); } Return 0; } 2) (10 pts) Write a function that takes three parameters: 2 sorted (in non-decreasing order) integer arrays and their length, and returns 1 if and only if there exists a number stored in both arrays. The function should return 0 otherwise. (For example, if array A stored 2, 3, 3, 5, 6 and array B stored 1, 4, 7, 8, 8, then the function should return 0. On the otherhand, if array A stored 2, 3, 4, 5, 6 and array B stored 3, 5, 9, 12, 15, then the function should return 1.) // Pre-condition: Arrays A and B are sorted in // non-decreasing order and are of length n. int commonitem(int A[], int B[], int n) { int i, j; for (i=0;i<n;i++){ for (j=0;j<n;j++){ if(A[i]== B[j]) return 1; } } return 0; } 3) (12 pts) What is the output of the function call f(3, 5), given the definition of f below: void f(int a, int b) { if (a == 0 || b == 0) printf("We are done.\n"); else { f(a+1, b-1); printf("Round %d: %d\n",a, a*b);
Background image of page 1

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

View Full DocumentRight Arrow Icon
} } ___We are done.________________
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Sampleexam1 - COP 3502 Computer Science I Exam #1 6/4/08...

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

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