View Code of Problem 48

#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main(){
    int n;
    scanf("%d",&n);
    if(n==1) printf("%.6f\n",2.0/1);
    double m=2.0,a=1.0,sum=2.0;
    for(int i=1;i<n;i++){
          double t=m,t1=a;
           m=t+t1;
           a=t;
          sum=sum+m/a;
       
	}
	   printf("%.6f\n",sum);
	/*double m=3.0,n=2.0;
	printf("%.6f",m/n);*/
	  return 0;
}

Double click to view unformatted code.


Back to problem 48