Zebra0.com

cpp recursionFind half of a number recursively

Find half of a number recursively

In this example, the function half receives a number. If the number is > 0, we print the number and then call half passing number/2. Notice that this is an integer. If we try this with a double, we will get what amounts to an endless loop.

half