Ask Question

Write the code to input a number and print the square root. Use the absolute value function to make sure that if the user enters a negative number

+3
Answers (1)
  1. 5 October, 16:28
    0
    Code is in c+ + and java.

    Explanation:

    C+ + Code

    #include

    #include

    using namespace std;

    int main ()

    {

    float number;

    //input the value

    cout<<"Enter a number to get square root: ";

    cin>>number;

    / / applying absolute to input number

    number = abs (number);

    / / calculate the square root

    float result = sqrt (number);

    cout<<"square root of "<
    double number = scanner. nextDouble ();

    number = Math. abs (number);

    double result = Math. sqrt (number);

    System. out. println ("square root of "+number+" is = "+result);

    }

    }

    Output

    Case 1:

    Enter a number to get square root: 9

    square root of 9 is = 3

    Case 2:

    Enter a number to get square root: - 9

    square root of 9 is = 3
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the code to input a number and print the square root. Use the absolute value function to make sure that if the user enters a negative ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers