用c++求1+1/2+1/3+1/4+1/n的近似值,要求至少累加到1/n不大于0.00984为止,输出循环次数的累加和

如题所述

#include <stdio.h>
int main()
{int n;
 double s=0;
 n=1;
 do
 {s+=1.0/n;
 }while(1.0/n++>0.00984);
 printf("n=%d\ns=%.8lf\n",--n,s);  
 return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答