Advertisement
immuntasir

Square Root without using any function

Jun 9th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. int main() {
  3.     double num,high, low, mid;
  4.     printf("Please enter a number: \n");
  5.     scanf("%lf", &num);
  6.     low = 0;
  7.     high = num;
  8.     int a = 100;
  9.     while (a--) {
  10.         mid = low + (high-low)/2;
  11.         if (mid*mid > num) high = mid - 10e-7;
  12.         else if (mid*mid < num) low = mid + 10e-7;
  13.         else break;
  14.     }
  15.     printf("Square-Root: %.6lf\n", mid);
  16.     main();
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement