Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Help with dividing number by 2 homework

$
0
0
Make a function called half() that takes an integer argument. The function must print the number it received to the screen, then the program should divide that number by two to make a new number. If the new number is greater than zero the function then calls the function half() passing it the new number as its argument. If the number is zero or less than the function exits

Call the function half() with an argument of 100, the screen output should be
100
50
25
...
...
1

please suggest meh the correct coding for this
I have tried it with for loop, do-while loop, while loop, if statement still em not getting the answer.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>