Answer to Question #57985 in C++ for sadeq

Question #57985
Write a program to read X and print Sin X if X>0, square root X if X<0
and absolute X if X/2 is integer.
1
Expert's answer
2016-02-24T00:01:01-0500
#include <iostream>

using namespace std;

void main()

{
double X, halfx = 0;
cout << "Please enter X: ";
cin >> X; // input some number
if (X > 0) // print sin X if X>0
{
cout << "sin(" << X << ") = " << sin(X) << endl;
}
if (X <= 0) // print square root X if X<0
{
cout << "sqrt(" << X << ") = " << sqrt(abs(X)) << "i" << endl;
}
if ((X / 2) == int((X / 2))) // print absolute X if X/2 is integer

{
cout << "abs(" << X << ") = " << abs(X) << endl;
}
system("pause");
}

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
APPROVED BY CLIENTS