Computers and Technology

#include using namespace std;
//Barry Bruin is learning about recursion, and attempted to write a
//program that recursively determines whether a provided integer's
//digits are in non-decreasing order (that is, they are in increasing
//order, but not necessarily strictly increasing order). As is, the
//program currently always outputs false, asserting that the digits
//are not in non-decreasing order. Run the program with several
//different inputs to verify this
//Your job is to fix the code so that it gives the correct output for
//all possible inputs. Only make changes where the code indicates
//that they should be made: you should not change the main function,
//nor the start of the helper function. You may not use for, while,
//do while, or goto.
bool increasing(int a)
{
if (a > 0) {
//if the recursive call fails, don't bother to check further.
if (!increasing (a/10)) return false;
//the least significant digit
int last = a % 10;
//the second least significant digit, 0 if a < 10
int prev = (a / 10) % 10;
//make your changes only below this line.
if (prev <= last) return true;
return false;
}
return false;
}
//do not change the main function.
int main (int argc, char* argv[])
{
int x;
cin >> x;
cout << increasing(x) << endl;
return 0;
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:30, nourmaali
4.11 painting a wall (1) prompt the user to input integers for a wall's height and width. calculate and output the wall's area (integer). note that in this case there is a new line after each prompt. (submit for 1 point). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet (2) extend to also calculate and output the amount of paint in gallons needed to paint the wall (floating point). assume a gallon of paint covers 350 square feet. store this value in a variable. output the amount of paint needed using the %f conversion specifier. (submit for 2 points, so 3 points total). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet paint needed: 0.471429 gallons (3) extend to also calculate and output the number of 1 gallon cans needed to paint the wall. hint: use a math function to round up to the nearest gallon. (submit for 2 points, so 5 points total). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet paint needed: 0.471429 gallons
Answers: 3
image
Computers and Technology, 22.06.2019 01:50, bessieyounger1211
Click on this link toopens a new window. bring up a flowchart in a new browser window. based on this flowchart, would a d-link 3347 gateway with an xbox 360 multiplayer problem be in scope or out of scope
Answers: 2
image
Computers and Technology, 22.06.2019 13:00, Cookie320
Write a program which asks you to enter a name in the form of first middle initial last. so you might enter for example samuel p. clemens. use getline to read in the string because it contains spaces. also, apparently the shift key on your keyboard doesn’t work, because you enter it all lower case. pass the string to a function which uses .find to locate the letters which need to be upper case and use toupper to convert those characters to uppercase. the revised string should then be returned to main in the form last, first mi where it will be displayed.
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, hannahliebl2000
Need asap write a short paper describing the history and differences between six sigma, waterfall, agile, and scrum models. understanding these models can give you a good idea of how diverse and interesting it development projects can be. describe what the rationale for them is and describe their key features. describe the history behind their development. at least 400 words
Answers: 1
Do you know the correct answer?
#include using namespace std;
//Barry Bruin is learning about recursion, and attempted to wri...

Questions in other subjects:

Konu
Mathematics, 31.07.2019 04:00
Konu
Biology, 31.07.2019 04:00