Skip to content

Commit 1102d56

Browse files
authored
Merge pull request #590 from PiyushPawar17/square_root_in_cpp
Added Babylonian Square Root in C++
2 parents 58f1cef + 2c4e21c commit 1102d56

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <iomanip>
3+
using namespace std;
4+
5+
double square_root(double num) {
6+
7+
double x = num;
8+
double y = 1;
9+
double e = 0.00000001;
10+
11+
while (x - y > e) {
12+
x = (x + y) / 2;
13+
y = num / x;
14+
}
15+
return x;
16+
}
17+
18+
int main() {
19+
20+
cout << setprecision(10) << square_root(6);
21+
return 0;
22+
}

0 commit comments

Comments
 (0)