求各位大佬帮忙,求1/1*2+1/2*3+...+1/n*(n+1)直到某一项小于0.001为止
#include<stdio.h>int main()
{
int n=1;
double k,S=0;
k=(float)(1/(n*(n+1)));
while(k>=0.001)
{
S+=(float)(1/(n*(n+1)));
n++;
}
printf("%lf\n",S);
return 0;
}
#include <stdio.h> int main( void ) { double s = 0; for( unsigned n=1; n*(n+1)<=1000; ++n ) s += 1.0/(n*(n+1)); printf( "%.3f\n", s ); }
#include <stdio.h> int main( void ) { double s = 0; for( unsigned n=1; (n-1)*n<=1000; ++n ) s += 1.0/(n*(n+1)); printf( "%.3f\n", s ); }