1 solutions
-
0
C :
#include<stdio.h> int main(void) { int x1,x2,x3,y1,y2,y3,N; scanf("%d",&N); if(N==1) printf("2\n"); else { if(N==2) printf("3.5\n"); else { int i; double s=3.5; x1=2; x2=3; y1=1; y2=2; for(i=3;i<=N;i++) { x3=x1+x2; y3=y1+y2; s+=x3*1.0/y3; x1=x2; x2=x3; y1=y2; y2=y3; } printf("%.2f\n",s); } } }C++ :
#include <bits/stdc++.h> using namespace std; long long n; float s,a=2,b=1,t; int main() { cin>>n; for(int i=1;i<=n;i++) s=s+1/b*a,t=b+a,b=a,a=t; printf("%.2f",s); return 0; }
- 1
Information
- ID
- 19050
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By