Programs that use arithmetic, those confined to using the integers that are greater than or equal to
Fantastic news! We've Found the answer you've been seeking!
Question:
somehow has become disabled. But there is a basic machine operation called 'succ()' - short for a successor - that calculate the successor to its integer argument. Here's the definition of the:
succ() function:
def succ(n):
return n+1
build a fruitful function that simulates the add() function. You can do this
using this definition:
def add(m, n):
if m == 0:
return n
if n == 0:
return m
return add(m - 1, succ(n))
(recursive) function just calls itself "counting down" the first argument and incrementing the second argument until the first argument is zero. There are other ways to
accomplish the same thing.
Somehow the * operation in your programming just broke as well! For this exercise, your job is to fruitful a function called 'mpy(m,n)' - for multiply - that calculates the product of m x n but without using the * operator. You will need to do something like what was done for the add function. Remember that multiplication is just repeated addition. So, m x n is just a way of saying add n to a sum (that starts at zero) m times.
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date: