Input: 173
Expected Output: 7
We were given this activity 2 days old and still couldn't solve this mystery. Here's my own code which doesn't match the given expected output above:
#include<iostream>
using namespace std;
int main() {
int num, result;
cin >> num;
if(num > 0) {
result = num % 10;
num / 10;
cout << result;
}
return 0;
}
You separate only the last digit, but need to check all - just add a loop. Also num / 10
does nothing.
maxdigit = 0;
while (num > 0) {
maxdigit = max(maxdigit, num % 10);
num /= 10;
}
cout << maxdigit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With