69,369
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int main()
{
int a = 2, b = 1;
int c = 3, d = 2;
float f = (float)a/(float)b + (float)c/(float)d;
int p,q;
for (int i = 0; i < 20 ; i++)
{
p = a + c;
q = b + d;
f += (float)p/(float)q;
a = c;
b = d;
c = p;
d = q;
}
cout<<f<<endl;
return 0;
}
a[20] = {2.0, 3.0};
b[20] = {1.0, 2.0};
sum = 0;
sum += a[0]/b[0] + a[1]/b[1];
for(i=2;i<20;i++)
{
a[i] = a[i-1]+a[i-2];
b[i] = b[i-1]+b[i-2];
sum += a[i]/b[i];
}