human
What is a code to largest number with maximum trailing nines which is less than N and greater than N and the other steps required given the following:
Largest number with maximum trailing nines which is less than N and greater than N | function to count no of digits.
function to implement above approach.
if difference between power and n doesn 't exceed d.
loop to build a number from the appropriate no of digits containing only 9.
if the build number is same as original number ( n ).
observation.
Driver Code.
variable that stores no of digits in n"
Solution in Python:
assistant
#Here is code to largest number with maximum trailing nines which is less than N and greater than N and the other steps required.
 def dig ( a ) :
	count = 0 ;
	while ( a > 0 ) :
		a /= 10
		count += 1
	return count
def required_number ( num , n , d ) :
	flag = 0
	power = 0
	a = 0
	for i in range ( num , 0 , - 1 ) :
		power = pow ( 10 , i )
		a = n % power
		if ( d > a ) :
			flag = 1
			break
	if ( flag ) :
		t = 0
		for j in range ( 0 , i ) :
			t += 9 * pow ( 10 , j )
		if ( n % power == t ) :
			print ( n , end = " " )
		else :
			print ( ( n - ( n % power ) - 1 ) , end = " " )
	else :
		print ( n , end = " " )
if __name__ == " _ _ main _ _ " :
	n = 1029
	d = 102
	num = dig ( n )
	required_number ( num , n , d )