int a = 2, b = 1; //设数列每项都是a/b
double sum = 0; //各项和
for (int i = 1; i <= 20; ++i) //循环20次
{
sum = sum + 1.0*a/b; //因为a/b是整数除法,会丢失小数部分,所以先*1.0让它变成double类型
int temp = a; //以下的程序让a和b各自增加
a = a + b;
b = temp;
}
float n=2;
float m=1;
float count =0;
for (int i=0;i++;i<20)
{
count+=n/m;
int t=n;
n=n+m;
m=n;
}