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.

Expert's answer

#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");
}
LATEST TUTORIALS
APPROVED BY CLIENTS