Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums



Programming Languages A Place for windows applications programs and programmers .

Programming Languages Thread, C program to compute the generalized Fibonacci numbers in Programming , WebDesign & Development; C program to compute the generalized Fibonacci numbers Fn(A,B), defined by two parameters. Solutions for the code to return Fn(5,7) ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=27593


Reply
LinkBack Thread Tools Display Modes
C program to compute the generalized Fibonacci numbers
 
 
Senior Member

Reply With Quote
 
Join Date: Dec 2008
Posts: 18,119
10-02-2009, 11:10 PM
 
C program to compute the generalized Fibonacci numbers Fn(A,B), defined by two parameters. Solutions for the code to return Fn(5,7) = 7476775332607909. largestFib.h long long largestFib(int A, int B); largestFib.c #include ...

C program to compute the generalized Fibonacci numbers Fn(A,B), defined by two parameters. Solutions for the code to return Fn(5,7) = 7476775332607909.

largestFib.h
long long largestFib(int A, int B);

largestFib.c
#include
#include "largestFib.h"

long long largestFib(int A, int B)
{
long long old1, previous1, next1;
double old2, previous2, next2;
long long next;

old1 = 0;
previous1 = 1;
next1 = 1;
old2 = 0;
previous2 = 1;
next2 = 1;
next = 1;

while(next1 == next)
{
old1 = A * old1;
previous1 = B * previous1;
next1 = old1 + previous1;
old1 = previous1;
previous1 = next1;

old2 = A * old2;
previous2 = B * previous2;
next2 = old2 + previous2;
old2 = previous2;
previous2 = next2;
next = (long long)(next2 + 0.01);

}

return old1;
}

main.c
#include "largestFib.h"

int main (int argc, char*argv[])
{
int A, B;

printf("Input two positive integers for Fn(A,B) to compute the largest Fibonacci number\n");
scanf("%d %d", &A,&B);

printf("The largest Fn(%d,%d) Fibonacci number is %lld\n", A,B,largestFib(A,B));

return 1;
}
 
 
 
Reply

Programming Languages Thread, C program to compute the generalized Fibonacci numbers in Programming , WebDesign & Development; C program to compute the generalized Fibonacci numbers Fn(A,B), defined by two parameters. Solutions for the code to return Fn(5,7) ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=27593


Bookmarks

Tags
compute, fibonacci, generalized, numbers, program


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On