Answer to Question #319505 in C++ for Greys

Question #319505

Create a program that will allow user to enter an integer number and display its square root and absolute value

1
Expert's answer
2022-03-28T11:00:54-0400
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n;

    cout << "Enter an integer: "; 
    cin >> n;
    cout << "It\'s absolute value is " << abs(n) << endl;

    if (n >= 0) {
        cout << "It\'s square root is " << sqrt(n) << endl;
    }
    else {
        cout << "It has no real square root" << endl;
    }

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog