Answers for "function to calculate square root in c++"

C++
1

Finding a square-root of a number in C++

#include <cmath> //library for the function 

sqrt(variable);
Posted by: Guest on October-01-2021
0

how to make a square root function in c++ without stl

double SqrtNumber(double num)
{
    double lower_bound=0; 
    double upper_bound=num;
    double temp=0;

    while(fabs(num - (temp * temp)) > SOME_SMALL_VALUE)
    {
           temp = (lower_bound+upper_bound)/2;
           if (temp*temp >= num)
           {
                   upper_bound = temp;
           }
           else
           {
                   lower_bound = temp;
           }
    }
    return temp;
 }
Posted by: Guest on June-05-2021

Code answers related to "function to calculate square root in c++"

Browse Popular Code Answers by Language