Question
The concept of multiplication can be defined recursively as follows: [1 mark] If m and n are two positive integers, m * n = m,
The concept of multiplication can be defined recursively as follows: [1 mark]
If m and n are two positive integers, m * n = m, if n = 1; or m * n = n, if m = 1; or m*n = m + m*(n-1)
Select from the following methods the one that best describes the above algorithm.
Select one:
a. static int multiply(int m, int n) { if (m == 1) return n; else if (n == 1) return m; else return multiply(m, n - 1); }
b. static int multiply(int m, int n) { if (m == 1) return n; else if (n == 1) return m; else return m + multiply(m, n - 1); }
c. static int multiply(int m, int n) { if (m == 1) return n; else if (n == 1) return m; else return m + (m, n - 1); }
d. static int multiply(int m, int n) { if (m == 1) return n; else if (n == 1) return m; else return m + m * (n-1); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started