Recursive Function 'mystery' and its Computation - Prof. Marjory Baruch, Lab Reports of Computer Science

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

Pre 2010

Uploaded on 08/09/2009

koofers-user-9y0
koofers-user-9y0 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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)

Partial preview of the text

Download Recursive Function 'mystery' and its Computation - Prof. Marjory Baruch and more Lab Reports Computer Science in PDF only on Docsity!

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)