Q:

Write a C++ program to find the square root of a number using Babylonian method

0

Write a C++ program to find the square root of a number using Babylonian method

Sample Input: n = 50
Sample Output: 7.07107

Sample Input: n = 81
Sample Output: 9

Sample Output:

Square root of 50 is 7.07107
Square root of 81 is 9

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

using namespace std; 

float square_Root(float num) 
    { 
        float x = num; 
        float y = 1; 
        float e = 0.000001;
        while (x - y > e) { 
            x = (x + y) / 2; 
            y = num / x; 
        } 
        return x; 
    } 
  
int main() 
{ 
    int n = 50; 
    cout << "Square root of " << n << " is " << square_Root(n); 
    n = 81; 
    cout << "\nSquare root of " << n << " is " << square_Root(n);     
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now