Square root Algorithm in C++

 Here is the way you can find the square root of any number by writing your own code in c++. 


#include<iostream>

using namespace std;


double sqrt(double num){


double stop_condition = 0.00000001;


double guess = num/2;


while((guess-num/guess) > stop_condition){

guess = (guess+num/2)/2;

}


return guess;

}



int main(){

double num = 4;


cout<<"The result is: "<<sqrt(num)<<endl;


return 0;

}

Comments

Popular posts from this blog

OOP Assignment 3 helping materials

OOP lab 7 task solution