29 lines
450 B
C++
29 lines
450 B
C++
//分子序列求和
|
|
#include<iostream>
|
|
#include<iomanip>
|
|
|
|
using namespace std;
|
|
|
|
int main(){
|
|
int n;
|
|
double a=2,b=1,c,d;
|
|
cin >>n;
|
|
|
|
if (n > 100)
|
|
{
|
|
cout <<"输入的数字太大了!"<<endl;
|
|
return 1;
|
|
}
|
|
|
|
double sum=0;
|
|
for (int i = 1; i <= n; i++)
|
|
{
|
|
sum += a/b;
|
|
c = a;
|
|
d = b;
|
|
a = a+d;
|
|
b = c;
|
|
}
|
|
cout <<fixed<<setprecision(2)<<sum<<endl;
|
|
return 0;
|
|
} |