vertc

21-11

Nov 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main () {
  8.     long double p, E;
  9.     int L;
  10.     cout<<"Podaj liczbe podpierwiastkowa (p):"<<endl;
  11.     cin>>p;
  12.     cout<<"Podaj dokladnosc obliczen (E): "<<endl;
  13.     cin>>E;
  14.     cout<<"Podaj liczbe literacji (L): "<<endl;
  15.     cin>>L;
  16.     long double a=p;
  17.     int i=0;
  18.     while(fabs(a - (p/a)>E) && i<L) {
  19.         a = (a+(p/a)) / 2;
  20.         i++;
  21.         cout<<a<<"\t";
  22.     }
  23.     cout<<endl<<"Wartosc wynosi: "<<setprecision(15)<<a;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment