Problem H: 计算数列和2/1,3/2,5/3,8/5......
#include<stdio.h> int main(){ int i,n; scanf("%d",&n); float sum=0.0; float a=1; float b=2; for(i=1;i<=n;i++){ sum=sum+1.0*b/a; int c=a; a=b; b=c+b; } printf("s=%.2f\n", sum); return 0; }
#include<stdio.h> int main(){ int i,n; scanf("%d",&n); float sum=0.0; float a=1; float b=2; for(i=1;i<=n;i++){ sum=sum+1.0*b/a; int c=a; a=b; b=c+b; } printf("s=%.2f\n", sum); return 0; }