27 lines
383 B
C++
27 lines
383 B
C++
|
#include <iostream>
|
||
|
#include <iomanip>
|
||
|
#include <cmath>
|
||
|
using namespace std;
|
||
|
int main(){
|
||
|
double c,eps,pom,liczba;
|
||
|
int i=0;
|
||
|
cin>>c>>eps;
|
||
|
liczba=c;
|
||
|
|
||
|
do{
|
||
|
pom=liczba;
|
||
|
liczba=0.5*(pom+c/pom);
|
||
|
i++;
|
||
|
}while(abs(liczba-pom)>eps);
|
||
|
|
||
|
int prec=1;
|
||
|
while(eps!=1){
|
||
|
eps=eps*10;
|
||
|
prec++;
|
||
|
}
|
||
|
|
||
|
cout<<setprecision(prec)<<"x_"<<i<<"="<<liczba;
|
||
|
return 0;
|
||
|
}
|
||
|
|