Today I got a homework from my university and I had the surprise that I am unable to solve it. It wants me to find the value of the following expression (fibonacci(n) / factorial(n)) using some functions, but in the end it would print 0 no matter what values I type in. The fibo function calculates the nth fibonacci number, the fact function calculates n! and the expression function calculates the value of fibo(n) / fact(n). I declared the expression function as a float because fact > fibo in every case for n > 1.
#include <stdio.h>
int fibo(int n) {
int a0 = 0, a1 = 1, t;
for (int i = 2; i <= n; ++i) {
t = a0 + a1;
a0 = a1;
a1 = t;
}
return t;
}
int fact(int n) {
int f = 1;
if (n <= 1) return f;
for (int i = 2; i <= n; ++i) {
f *= i;
}
return f;
}
float expression(int n) {
float exp = fibo(n) / fact(n);
printf("%f\n", exp);
return exp;
}
void main () {
int n;
printf("Type your number: ");
scanf("%d", &n);
printf("fibo = %d\n", fibo(n));
printf("fact = %d\n", fact(n));
printf("%f", expression(n));
}```