1. Originally Posted by Afik
why it say that in length of digits the number is 4900, and not both in sum and in length is 7963
That's because both 4900 and 7963 are 4 digit numbers. 4900 came first, so it holds the distinction of being the number with the max length. Therefore, the output is correct.

You can of course have more complicated "tiebreaker" requirements, e.g., if there is more than one number with the max length, pick the number that also has the max digit sum, but then you're going to have to change your implementation to handle this, e.g., store all the current known numbers with max length in an array, and all the current known numbers with max digit sum in another array, then compute the intersection of the two arrays. So, it can be done, but I'd suggest checking the requirements with your teacher first.

2. Originally Posted by laserlight
That's because both 4900 and 7963 are 4 digit numbers. 4900 came first, so it holds the distinction of being the number with the max length. Therefore, the output is correct.

You can of course have more complicated "tiebreaker" requirements, e.g., if there is more than one number with the max length, pick the number that also has the max digit sum, but then you're going to have to change your implementation to handle this, e.g., store all the current known numbers with max length in an array, and all the current known numbers with max digit sum in another array, then compute the intersection of the two arrays. So, it can be done, but I'd suggest checking the requirements with your teacher first.

ok, how I do this? can you help me? I want to do more complicated "tiebreaker".....

3. Firstly, are you sure you need to do this? Ask your teacher to be sure. It is good practice, but introducing complexity increases the chance of a bug. I'm guessing you're not using version control, so at the very least you should save a copy of your current working code to submit in case you mess this up.