二分法求平方根+循环输入以回车结束

 double sqrt1(double x)

{

double eps=0.00001;

double low=0.0;

double high=x;

double mid=(low+high)/2;

while((high-low)>eps)

{

if(mid*mid>x)

{

high=mid;

}

else

{

low=mid;

}

mid=(high+low)/2;

return mid;

}

#include <iostream>
using namespace std;
 
int main()
{
    int a, s=0;
    //回车表示数据输入结束
    while(cin.peek()!='\n')  //cin.peek()相当于偷看一眼再放回流中
    {
        cin>>a;
        s += a;
    }
    cout << s;
    return 0;

 }

猜你喜欢

转载自blog.csdn.net/m0_46717588/article/details/119237530