Write a program using C language to solve there is a fractional sequence: 2/1,3/2,5/3,8/5,13/8,21/13 ... find the first 20 items of this sequence
void Test () {///idea: rule-based starting from 3/2 the denominator of the next number is the numerator of the previous number, the next number of numerator is the numerator of the previous number of the denominator and double mol = 2.0, den = 1.0, denlast = 0; Double Div = Mol/den; Double sum = 0; int i = 0; for (i = 0; i < i++) {printf ("%g/%g", Mol, den),//%g omitting the invalid floating-point number 0 sum + = div; Denlast = den; den = mol; MOL + = Denlast; div = Mol/den; } printf ("\nsum =%lf\n", sum);//%lf_ double-precision}
650) this.width=650; "title=" qq20160211112631.jpg "src=" http://s5.51cto.com/wyfs02/M02/7A/D4/ Wkiol1a8ahpx3e1uaadjajvo3ze888.jpg "alt=" Wkiol1a8ahpx3e1uaadjajvo3ze888.jpg "/>
The
uses the C language program to solve a fractional sequence: 2/1,3/2,5/3,8/5,13/8,21/13 ... find the first 20 items of this sequence