Consider the Java function: public static float f(long m, long n) { float result = (float)m / (float)n; if (m < 0 || n < 0) return 0.0f; else result -= f(m * 2, n * 3); return result; } Which value best approximates f(1, 3)?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. 0.2
Explanation
f(1,3) = 1/3 − 2/9 + 4/27 − … until the longs overflow to negative and return 0. The alternating geometric series sums to (1/3)/(1 + 2/3) = 0.2.
More Programming Languages and Computer Graphics questions
- In the context of 3D Computer graphics, which of the following statements is/are correct? (A) Under perspective projection, each set of par…
- Concerning phong shading and Gouraud shading in a 3D scene, which of the following statements are true? (A) Gouraud shading requires more c…
- Match List-I with List-II. List I gives matrices representing 2D transformations and List-II shows the corresponding transformation diagram…
- Given below are different properties of 3D projections from A-D. Identify the correct order on the basis of property true of (i) a perspect…
- Given below are two statements: Statement I : Bezier curves are curves that interpolate all of their control points. Statement II : A cubic…
- What is the output? int i, j, x = 0; for (i = 0; i < 5; ++i) for (j = 0; j < i; ++j) { x += (i + j − 1); break; } printf("%d", x);