有一个分数序列,2/1,3/2,5/3,8/5,13/8。。。求前二十项之和
#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[])
{int n=1,a=2,b=1,c=0,d=0,j=0;
while(n<=20)
{
c=a/b;
d=a+b;
b=a;
a=d;
j=j+c;
n++;
}
printf("%d",j);
return 0;
}
#include<stdio.h> int main() { int n = 1, a = 2, b = 1,d = 0; double c = 0, j = 0; while (n <= 20) { c = (double)a / (double)b; d = a + b; b = a; a = d; j = j + c; n++; } printf("%f", j); return 0; }