Finding number of digits in n 'th Fibonacci number | C ++ program to find number of digits in nth Fibonacci number ; This function returns the number of digits in nth Fibonacci number after ceiling it Formula used ( n * log ( phi ) - ( log 5 ) / 2 ) ; using phi = 1.6180339887498948 ; Driver program to test the above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long numberOfDigits ( long long n ) { if ( n == 1 ) return 1 ; long double d = ( n * log10 ( 1.6180339887498948 ) ) - ( ( log10 ( 5 ) ) / 2 ) ; return ceil ( d ) ; } int main ( ) { long long i ; for ( i = 1 ; i <= 10 ; i ++ ) cout << " Number ▁ of ▁ Digits ▁ in ▁ F ( " << i << " ) ▁ - ▁ " << numberOfDigits ( i ) << " STRNEWLINE " ; return 0 ; }