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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:30, ruddymorales1123
Linda subscribes to a cloud service. the service provider hosts the cloud infrastructure and delivers computing resources over the internet. what cloud model is linda using
Answers: 1
image
Computers and Technology, 22.06.2019 15:00, miracle9704
Atool that matches persoal skills qualities interests and talets to a career is called a
Answers: 1
image
Computers and Technology, 24.06.2019 08:10, anthonysutton82
Where are american poets found in the dewey decimal system
Answers: 1
image
Computers and Technology, 24.06.2019 15:00, mbede002
Who introduced the concept of combining artificial and natural light in the studio
Answers: 1
You know the right answer?
#include using namespace std;
//Barry Bruin is learning about recursion, and attempted to wri...

Questions in other subjects:

Konu
Mathematics, 06.07.2019 15:00
Konu
Mathematics, 06.07.2019 15:00