c++ - maximum 2 digits from a number -
In order to find the maximum number of values from user input number, my code is in 'Attempt': It works perfectly for most numbers, e.g. Like 34256, except for some cases, for example, when I input 54321, the maximum is 5, which is correct, but it allows maximum 2 to 1, which is not the desired value. Will you be very kind to help me find out my error? After saying this, here's a suggestion: inside
for the loop, you either < Value of the code> max1 or value of
max2 . But to make your code work in all cases, there should be a point within
for the
loop, where you change the value of both to
max1 and value of
Max 2 .
Zero Max 2 (int a, int and max 1, int and max2) {max 1 = 0; Maximum 2 = 0; (; A & gt; 0; a / = 10) {int temp = a% 10; If (Float> Max 1) {max2 = max1; Max 1 = Temporary; } And if (temp> max 2) {max2 = temp; }}}
Comments
Post a Comment