181k views
3 votes
Write, compile and test (show your test runs!) program that calculates and returns the fourth root of the number 81, which is 3. Your program should make use of the sqrt() method. Math.sqrt(number).

1 Answer

4 votes

Answer:

I am writing a JAVA program. Let me know if you want the program in some other programming language.

public class FourthRoot{ //class to calculate fourth root of 81

public static void main(String[] args) { //start of main() function body

double square_root; //declares to hold the fourth root of 81

double number=81; // number is assigned the value 81

/* calculates the fourth root of number using sqrt() method twice which means sqrt() of sqrt(). This is equivalent to pow(number,(0.25)) where pow is power function that computes the fourth root by raising the number 81 to the power of 0.25 which is 1/4 */

square_root=Math.sqrt(Math.sqrt(number));

//displays the fourth root of 81 i.e. 3

System.out.println("Fourth Root of 81 is "+ square_root); } }

Step-by-step explanation:

The program is well explained in the comments given along with each statement of the program . Since it was the requirement of the program to user Math.sqrt() method so the fourth root of number= 81 is computed by taking the sqrt() of 81 twice which results in the fourth root of 81 which is 3.

So the first sqrt(81) is 9 and then the sqrt() of the result is taken again to get the fourth root of 81. So sqrt(9) gives 3. So the result of these two computations is stored in square_root variable and the last print statement displays this value of square_root i.e. the fourth root of number=81 which is 3.

Another way to implement the program is to first take sqrt(81) and store the result in a variable i.e. square_root. After this, again take the sqrt() of the result previously computed and display the final result.

public class FourthRoot{

public static void main(String[] args) {

double square_root;

double number=81;

square_root=Math.sqrt(number);

System.out.println("Fourth Root of 81 is: "+ Math.sqrt(square_root)); } }

The program along with its output is attached in a screenshot.

Write, compile and test (show your test runs!) program that calculates and returns-example-1
User Cheech
by
5.4k points