Question

write a recursive function that returns true if the digits of a positive integer are in...

write a recursive function that returns true if the digits of a positive integer are in increasing order ; otherwise, the function returns false. Also write a program to test your function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;
bool isAscending(int n){
if(n == 0) return true;
if(n%10>(n/10)%10) return isAscending(n/10);
else return false;
}

int main()
{
int n;
cout << "Enter the number:" << endl;
cin >> n;
if(isAscending(n)) {
cout<<"Given number "<<n<<" is in increasing order"<<endl;
} else {
cout<<"Given number "<<n<<" is not in increasing order"<<endl;
}
return 0;
}

Output:

$g++ -o main *.cpp
$main
Enter the number:
Given number 1234 is in increasing order
Add a comment
Know the answer?
Add Answer to:
write a recursive function that returns true if the digits of a positive integer are in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT