Ask Question
20 June, 09:18

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

+2
Answers (1)
  1. 20 June, 12:13
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers