#include<iostream> using namespace std; int main() { int n=1; double s=0; do//先执行一次循环体 { s=s+(1.0/n); n++; }while(s<8.0); cout <<"s="<<s<<endl; cout <<"n="<<n<<endl; return 0; }
34.设s=1+1/2+1/3+…+1/n,求与8最接近的s的值及与之对应的n值
时间: 2024-11-26 06:46:52
#include<iostream> using namespace std; int main() { int n=1; double s=0; do//先执行一次循环体 { s=s+(1.0/n); n++; }while(s<8.0); cout <<"s="<<s<<endl; cout <<"n="<<n<<endl; return 0; }
34.设s=1+1/2+1/3+…+1/n,求与8最接近的s的值及与之对应的n值