Question
Ask the user about the initial integer input for both programs. 1. Make a function called half() that takes an integer argument. The function must
Ask the user about the initial integer input for both programs.
1. 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 itself (the function half()) passing it the new number as its argument. If the number is zero or less, then the function exits. (This technique is called recursion.)
Call the function half() with an argument of 100, then the screen output should be 100 50 25 ... ... 1
2. Write a program that does exactly the same as in the Program 1. But this time use the technique of repetition. Choose a looping that you find the most appropriate among while, for, do...while. You don't need to create a function in this program.
Compile and execute the program making sure that all syntax and logic errors are removed. Name the CPP file LastNameFirstInitial.cpp. For example, I would name my files LeeD1.cpp and LeeD2.cpp. Upload two files for this assignment. Explain your program appropriately using comments (/* */, //) inside the CPP file.
This is C++
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