95.4k views
5 votes
Assume the availability of a function named oneMore. This function receives an integer and returns one more than its parameter. So, pass oneMore( 12) and it will return 13. DO NOT DEFINE this function-- just assume it is available. YOUR TASK: write an expression whose value is 5 but in your expression you can only use the integer literal 0. You can not use anything with the digits 1-9 and you cannot use any arithmetic operators like + - * /. But you can use 0 and you can make calls to the function oneMore.

User Private
by
5.5k points

1 Answer

2 votes

Answer:

oneMore(oneMore(oneMore(oneMore(oneMore(0)))))

Step-by-step explanation:

  • As a function has been explained which when given an integer results as a next integer. oneMore(given-integer)= next integer
  • As we are restricted to use 0 only and can't use operators like + - * /.
  • We have to obtain a value 5
  • So doing step-by-step:

(oneMore(0))=1

(oneMore(oneMore(0)))=2

(oneMore(oneMore(oneMore(0))))=3

(oneMore(oneMore(oneMore(oneMore(0)))))=4

oneMore(oneMore(oneMore(oneMore(oneMore(0)))))=5