
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An explanation of a recursive function named 'mystery' along with an example of its computation. The function takes two integer arguments, 'm' and 'n'. If 'n' equals 1, the function returns 'm'. Otherwise, it returns the sum of 'm' and the result of the function called with arguments 'm' and 'n-1'. The document also includes a table showing the values of 'm' and 'n' for a specific example, as well as the value of 'mystery(m,n)' for that pair.
Typology: Lab Reports
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Figure 10.2 from Hanley and Koffman (modified) int mystery(int m, int n) { int ans; if (n == 1) /* simple case / ans = m; else / recursive step */ ans = m + mystery(m, n-1); return (ans); } compute mystery(5, 4); Notice m stays the same. Recursion is on n, which is 4 in our example Make a table m n mystery(m,n)