#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;
}
how do we use loops in c plus plus programing and what are basic differences between do,for and while loop
i dn't know. haha
No.
bghjg
#include <iostream> int main() { for(int i=51; i <= 100; i+=2) { cout << i << endl; } return 0; }
Fibonacci numbers
Print "Type the upper limit (n) ?" Input n K = -1 WHILE K < = n K = K + 2 Sum = Sum + K WEND Print "The sum of all odd numbers up to "; n; "is "; Sum
10 print "That is not a question." 20 print "That is a command." 30 end
std::cout<<"computer"<<std::endl;
how to write a program that counts automorphic number from 1 to 999
#include #include void main() { clrscr() int a=0,b=1,c,i,n; coutn cout
By learning how to program on C+.