answersLogoWhite

0


Best Answer

/*Java program to find out square root of a given number

* without using any Built-In Functions

*/

public class SquareRootDemo2

{

public static void main(String[] args)

{

//Number for which square root is to be found

double number = -12;

//This method finds out the square root

findSquareRoot(number);

}

/*This method finds out the square root without using

any built-in functions and displays it */

public static void findSquareRoot(double number)

{

boolean isPositiveNumber = true;

double g1;

//if the number given is a 0

if(number==0)

{

System.out.println("Square root of "+number+" = "+0);

}

//If the number given is a -ve number

else if(number<0)

{

number=-number;

isPositiveNumber = false;

}

//Proceeding to find out square root of the number

double squareRoot = number/2;

do

{

g1=squareRoot;

squareRoot = (g1 + (number/g1))/2;

}

while((g1-squareRoot)!=0);

//Displays square root in the case of a positive number

if(isPositiveNumber)

{

System.out.println("Square roots of "+number+" are ");

System.out.println("+"+squareRoot);

System.out.println("-"+squareRoot);

}

//Displays square root in the case of a -ve number

else

{

System.out.println("Square roots of -"+number+" are ");

System.out.println("+"+squareRoot+" i");

System.out.println("-"+squareRoot+" i");

}

}

}

User Avatar

Wiki User

โˆ™ 2013-06-10 10:26:14
This answer is:
User Avatar
Study guides

Algebra

20 cards

A polynomial of degree zero is a constant term

The grouping method of factoring can still be used when only some of the terms share a common factor A True B False

The sum or difference of p and q is the of the x-term in the trinomial

A number a power of a variable or a product of the two is a monomial while a polynomial is the of monomials

โžก๏ธ
See all cards
3.74
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
834 Reviews

Add your answer:

Earn +20 pts
Q: To find square root of a nos without using built in function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
People also asked