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;
}