Finding square root without using sqrt funcion.

So, my professor wants us to find roots of a function without using any pre-made functions...I write my program till I need the square root...I know I should create a function myself but I just learned making functions and really don't know how. I'd appreciate the help.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #include <iostream>
using namespace std;
int main()
{
	int a;
	int b;
	int c;
	int Delta;
	cout<<"enter 3 numbers"<<endl;
	cin>>a>>b>>c;
	Delta=b*b - (4*a*c);
		if(Delta>0)
		{
			cout<<"X1:"<<((-b + sqrt(Delta))/2*a<<endl;	//Now I can't use sqrt...what else can I do?
			cout<<"X2:"<<((-b - sqrt(Delta))/2*a<<endl;	//that's how much I did
There are math sites that will cover how to calculate a square root by hand. You should be able to google that phrase and find them. I used the "guess-divide-average" way when I had to do this. Then you just need to translate that by hand algorithm into C++. Figure out how accurate you want to be, e.g. is within .001 of the actual square good enough?

You can create your own function "mySqrt" (or whatever you want to call it) and call that instead of the one in the <cmath> header.
Many methods on this page. Personally, think the easiest to implement will be
http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
Topic archived. No new replies allowed.