#include <iostream>
#include <conio>
#include <math>
int main()
{
double x=0.25;
cout<<"x^(1/2) is "<<pow(x,(1/2))<<endl; //answer should be 0.5 (but it gave "1")
cout<<"cos(x) is "<<cos(x)<<endl; //the answer is in radian, how to make it in Degree?
cout<<"sin(x) is "<<sin(3)<<endl; //the answer is in radian, how to make it in Degree?
cout<<"x^7 is "<<pow(x,7)<<endl;
cout<<"((x^3)+(x^7))/x is "<<(pow(x,3)+pow(x,7))/x<<endl;
cout<<"sqrt|7-9| is "<<sqrt(7-9)<<endl; //how to make it sqrt|7-9|<-Modulus?
getch();
return 0;
}
Hi, can anyone tell me how to correct the error about? I've put the question inside the comment...TQ...
Thanks...
@hamsterman
for the line 7, is that I can use 1.0/2, 1/2.0 and 0.5?
for lines 8 and 9, is there any function in C++ like "deg"? instead of doing math like radian*180/3.1415 ?
for line 12, I tried both abs and fabs, they works fine, is that "fabs" is legal too? cout<<"sqrt|7-9| is "<<sqrt(fabs(7-9))<<endl;
TQ...
@iHutch105
1. how to use ToDegrees function?
2. actually 7-9=-2 but I want to take the magnitude of it only which is "2", is that I can use % also?
For 7 you could use 1.0/2 or 1/2.0 or 0.5 or 1./2 or 1/(float)2 or float(1)/2 or many similar variations. The important thing is to say that one of the numbers is not an integer.
There is no deg. Like iHutch105 said, you can write one. Here: double deg(double rad) { return rad*108/3.1415; }
I wrote a "?" because I remembered using abs, but in a reference only saw fabs. I'm sure they're both fine.
% can't be used for absolute value. It only gives the remainder.
Inside what? I only said that there wasn't a function that could convert radians to degrees in the standard library. Any kind of operation can be put into a function for your convenience.