Ask Question
11 January, 04:27

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

+5
Answers (1)
  1. 11 January, 05:00
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers