Computer Science, asked by amannishad0512p5zxh6, 11 months ago

Wap to find the squareroot of an number in java without using inbuilt function??


amannishad0512p5zxh6: Nobody would give any foolish answer !!
amannishad0512p5zxh6: To gain points or mark as brainlest batch !!

Answers

Answered by Anonymous
0
ber without using any built-in functions

Java Program


/*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");

        }

 

    }

}
pls mark me as brainlist

Anonymous: i cant see any request there
amannishad0512p5zxh6: [email protected]
amannishad0512p5zxh6: Kar loo okk
amannishad0512p5zxh6: I have to go to learn chemistry
amannishad0512p5zxh6: Meet you again tommorrow
Anonymous: okk byy
amannishad0512p5zxh6: "Organic chemisty "
Anonymous: i hv sent u msg
amannishad0512p5zxh6: I not get yet !!
Anonymous: but i hv sent msg
Answered by suvrahore20
1

Answer:

answer is in the picture given above

Similar questions