Advertisement
impressive_i

Calculating the square root

Aug 12th, 2019
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | None | 0 0
  1. /* Calculating the square root by iterations */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void) {
  6.     double num = 570.15;
  7.     double root = num / 2;
  8.     double eps = 0.01;
  9.     int iter = 0;
  10.     while( root - num / root > eps ){
  11.         iter++;
  12.         root = 0.5 * (root + num / root);
  13.         printf("Iteration: %d : root = %f\n", iter, root);
  14.     }
  15.     printf("root = %f", root);
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement