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

11y ago
This answer is:
User Avatar

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
Related questions

How do you sinx without using mathh or built in sin function Any Algorithm to implement sin function?

You can compute sin(x) manually/numerically using Taylor's Series.


How do you define power function without using operator?

using pow() function.. ..


How do you modulate in matlab without using matlab tools?

You would have to write your own code for a modulation (Matlab has a convolution function not in the tools), otherwise you can use its built in function in the signal processing toolbox.


How many rectangles can be built using a prime number of square tiles?

One.


Which math function is used to find the square root of a number using java?

Math.sqrt(number) function is used to find the square root of a number.. try it


How does the SUM function add all the number in a range?

SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.SUM is a built-in function with Excel that has been specially designed to sum a range of cells. It just needs to know what the cells are and then it can add them all up. The method of doing that has been programmed into Excel by its developers. This leaves us with the simple task of using the function without needing to know the specifics of exactly how it does it.


How do you calculate sine value without using math function?

Using its Taylor-series.


Sorting an array in PHP without using sort function?

plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++


How do you compare 2 numbers without using relational operators in c?

using max function


How do you implement awgn in MATLAB without using awgn function?

no way... use awgn function in matlab


Reverse of a string without using string handling function?

shashi


How do you reverse a string in PHP without using a function?

Without any function is impossible. So I'll assume you mean any coded function, in which case the predefined function below is your answer.$string = strrev($string);