subject

#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;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
question
Computers and Technology, 24.06.2019 17:30
When you type january in a cell, then copy it using the fill handle to the cells below and the data automatically changes to february, march, april, and so on, what is this feature called? auto fill automaticcopy monthfill textfill
Answers: 1
question
Computers and Technology, 24.06.2019 23:00
Hypertension occurs when blood pressure is too high.
Answers: 1
question
Computers and Technology, 24.06.2019 23:30
True or false when a host gets an ip address from a dhcp server it is said to be configured manually
Answers: 1
You know the right answer?
#include using namespace std;
//Barry Bruin is learning about recursion, and attempted to wri...
Questions
question
English, 21.11.2020 07:10
question
Health, 21.11.2020 07:10
question
Biology, 21.11.2020 07:10
question
Mathematics, 21.11.2020 07:10
question
Mathematics, 21.11.2020 07:10
question
Mathematics, 21.11.2020 07:10
Questions on the website: 13722360