answersLogoWhite

0

#include<iostream>

#include<iomanip>

#include<math.h> // for floor, log and pow

bool is_fib(unsigned num)

{

// Algorithm: num is Fibonacci if 5*num*num+4 or 5*num*num-4 is a perfect square.

// Note:

// Since 5*num*num could result in a huge number which could easily overflow,

// we'll use a modified algorithm that utilises numbers smaller than num.

double root5 = std::sqrt(5.0);

double phi = (1 + root5) / 2;

long idx = (long)floor( log(num*root5) / log(phi) + 0.5 );

long n = (long)floor( pow(phi, idx)/root5 + 0.5);

return (n == num);

}

int main()

{

// Print non-Fibonacci numbers in range: 0-50

for (unsigned num=0; num<=50; ++num)

if (!is_fib(num))

std::cout

<<std::setw(6)

<<num

<<" is not a Fibonacci number"

<<std::endl;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

C program to print numbers 1 to n?

how do we use loops in c plus plus programing and what are basic differences between do,for and while loop


Program to generate Fibonacci series using storage class in c plus plus?

i dn't know. haha


Do I need a C plus plus program to print PASCAL's triangle?

No.


C plus plus program to print number patterns?

bghjg


Write a program to print odd numbers In C plus plus between 51 to 100?

#include &lt;iostream&gt; int main() { for(int i=51; i &lt;= 100; i+=2) { cout &lt;&lt; i &lt;&lt; endl; } return 0; }


What is the name of the theorem that states that 1 plus 2 equals 3 plus 4 equals 7 plus 8 equals 15 plus 16 equals 31?

Fibonacci numbers


1 plus 3 plus 5 plus 7n how will you do this program?

Print "Type the upper limit (n) ?" Input n K = -1 WHILE K &lt; = n K = K + 2 Sum = Sum + K WEND Print "The sum of all odd numbers up to "; n; "is "; Sum


Write a program in BASIC to find the sum of the series s equals 2 plus 4 plus . plus 100?

10 print "That is not a question." 20 print "That is a command." 30 end


What are the steps in c plus plus program to print word computer?

std::cout&lt;&lt;"computer"&lt;&lt;std::endl;


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


Create a c plus plus program to generate Fibonacci series?

#include #include void main() { clrscr() int a=0,b=1,c,i,n; coutn cout


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.