Grafundzijus

saknies traukimas

Jan 1st, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     double a = 1.0, precision = 0.000001, b;
  12.  
  13.    
  14.     ifstream fr ("U1.txt");
  15.     ofstream fw ("U1rez.txt");
  16.     fr >> n;
  17.    
  18.  
  19.     while (a * a != n)
  20.     {
  21.         b = n / a;
  22.         a =(a + b) / 2;
  23.  
  24.         if (a < precision)
  25.         {
  26.             break;
  27.         }
  28.        
  29.        
  30.     }
  31.  
  32.  
  33.     fw << fixed << setprecision(6) << a;
  34.    
  35.     fr.close();
  36.     fw.close();
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment