Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago