#include <stdio.h> int main(int argc, char **argv) { int n = 20 , i = 0 ; double a = 1 , b = 2 , temp = 0 , count = 0 ; for (i = 0 ; i < n ; i++){ count = count + a/b; temp = a + b; a = b; b = temp; } printf("%lf",count); return 0; }
[此贴子已经被作者于2017-2-19 17:50编辑过]
#include <stdio.h> main () { float x,y,a,b,c,i; a=1,b=2,y=0; for(i=1;i<=20;i++) x=a/b,y=y+x, a=a+1,b=a+1; printf("%f\n",y); }
#include <stdio.h> int main(void) { int i; float a,b,c,num,sum; a=1; b=2; c=0; sum=0; for(i=1;i<=20;i++) { num=a/b; sum=sum+num; c=a+b; a=b; b=c; } printf("%5.3f\n",sum); getchar(); return 0; }