编写一程序段求s=1/2+1/6+1/12+…+1/(n(n-1))+…直到最后1项的值小于1e-6.
main(){
float s=0;
float flag=1;
float i=2;
while(flag>0.000001){
s= s + (float)1/(float)(i*(i-1));
flag=(float)1/(float)(i*(i-1));
i++;
}
printf(" %f",s);
}
main(){
float s=0;
float flag=1;
float i=2;
while(flag>0.000001){
s= s + (float)1/(float)(i*(i-1));
flag=(float)1/(float)(i*(i-1));
i++;
}
printf(" %f",s);
}