Square root

i need help finding square roots without the math library. what im using is this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  //square=total length of 1d array
void uMatrix::sqrt(int square)
{

		double root = square / 3;
		if (square <= 0)
			rows = 0;
		cols = 0;
		for (int i = 0; i < 100; i++) {
			root = ((root + square) / root) / 2;
		}
		rows = static_cast <int>(root);
		cols = static_cast<int>(root);
	
}

the reason im setting the answer to rows and cols is i am using them to create a 2d array.

root = ((root + square) / root) / 2;
Slightly wrong. The Babylonian algorithm is root = (root + square / root) / 2;
Last edited on
Topic archived. No new replies allowed.