View Code of Problem 48

#include<stdio.h>

int main(){
	double sum = 0;
	int n;
	float a = 2;
	float b = 1;
	float temp;
	int i ;
	printf("请输入正整数n,1<=n<=10:");
	scanf("%d",&n);    //  a/b 2/1 3/2 5/3 8/5 13/8
	for(i=1;i<=n;i++){
		//printf("%f/%f\n",a,b);
		sum = sum + a/b;
		//printf("%f\n",sum);
		temp = b;
		b = a;
		a = a + temp;
	}
	printf("%f",sum);
	return 0 ;
} 

Double click to view unformatted code.


Back to problem 48