This is math calculation that i need to program - define sequence an as
- a1 = 1
- a(n+1) = 1 / (2 × [an] - an + 1) where [x] is the floor function
If a2014 = p/q, find p + q
And, this is the code I tried:
#include <stdio.h>
#include <math.h>
main() {
int n=1;
double an=1.0;
double an_floor=0.0;
while (n<=2014) {
an_floor = floor(an);
an = 1 / (2*an_floor-an+1);
n = n + 1;
}
printf("%lf", an);
return 0;
}
Problems;
-
I cannot compile (using web complier such as codepad, etc.)
-
Don't know how to make result
-
Fraction result is wrong
Aucun commentaire:
Enregistrer un commentaire