Example #1
0
unsigned long long getFibonacci(int fibPlace)
{
	if (fibPlace == 0 || fibPlace == 1)
	{
		return 1;
	}

	return getFibonacci(fibPlace - 2) + getFibonacci(fibPlace - 1);
}
Example #2
0
	long Fibonacci::getFibonacci(int a, int b, long position, long max)
	{
		long c = a + b;
		if (position == max) return c;
		position++;
		return getFibonacci(b, c, position, max);
	}
Example #3
0
	long Fibonacci::getFibonacci(long max)
	{
		if (max == 0) return 0;
		if (max == 1) return 1;

		return getFibonacci(0, 1, 2, max);
	}
Example #4
0
void Menu::executeFIBONACCI() {
	int nMax = 0;

	cout << "\t피보나치 수 구하기 함수를 선택하셨습니다." << endl;
	cout << "■ 구하고자 하는 피보나치 수 개수 : ";
	cin >> nMax;

	int maxVal = getFibonacci(nMax);

	cout << "▶ " << nMax << " 번째의 피보나치 수는 " << maxVal << " 입니다." << endl;
}
Example #5
0
int main () 
{
	
 int sum = 0, i = 1, fibN; 

 do 
 {
	fibN = getFibonacci(i++);
	if ( fibN % 2 == 0) sum += fibN; 
 }
 while ( fibN < 4000000);

 printf("The sum of the even numbers is: \t%d\n", sum); 

 return 0; 
}
Example #6
0
void printFibonacciNumbers()
{
	int fibonacciPlace = 0;
	unsigned long long currFibonacci = 0;
	unsigned long long stopPoint = ULLONG_MAX / 2;
	while (currFibonacci <= stopPoint)
	{
		auto begin = std::chrono::high_resolution_clock::now();
		currFibonacci = getFibonacci(fibonacciPlace);
		auto end = std::chrono::high_resolution_clock::now();
		auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();

		//std::this_thread::sleep_for(std::chrono::milliseconds(500));

		mutex.lock();
		std::cout << "Fibonacci: " << currFibonacci << ", Time: " << duration << " ns" << std::endl;
		mutex.unlock();

		fibonacciPlace++;
	}
}