human
Nearest Fibonacci Number to N | Function to find the Fibonacci number which is nearest to N.
Base Case.
Initialize the first & second terms of the Fibonacci series.
Store the third term.
Iterate until the third term is less than or equal to num.
Update the first.
Update the second.
Update the third.
Store the Fibonacci number having smaller difference with N.
Print the result.
Driver Code"
Solution in Python:
assistant
#Here is code to nearest Fibonacci Number to N and the other steps required.
 def nearestFibonacci ( num ) :
	if ( num == 0 ) :
		print ( 0 )
		return
	first = 0
	second = 1
	third = first + second
	while ( third <= num ) :
		first = second
		second = third
		third = first + second
	if ( abs ( third - num ) >= abs ( second - num ) ) :
		ans = second
	else :
		ans = third
	print ( ans )
if __name__ == ' _ _ main _ _ ' :
	N = 17
	nearestFibonacci ( N )