-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusingcmath.cpp
54 lines (41 loc) · 1.23 KB
/
usingcmath.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cmath>
int main(int argc, char* argv[])
{
double x = 1.0, y = 2.0, z;
z = x/y; //division
std::cout << z << "\n";
z = x*y; //multiplication
std::cout << z << "\n";
z = sqrt(x); //square root
std::cout << z << "\n";
z = exp(x); //exponential function
std::cout << z << "\n";
z = pow(x,y); //x to the power of y
std::cout << z << "\n";
z = M_PI; //store value of pi
std::cout << z << "\n";
/* You can similarly to sqrt and exp use cos,
sin, tan, acos, asin, atan, cosh, sinh, tanh,
log10, ceil, floor */
double a = 7.8, b = 1.65, u = -3.4;
z = fmod(a,b); //remainder when x is divided by y
std::cout << z << "\n";
z = atan2(a,b); //inverse tangent in radians of
//angle between vector (x,y) and
//pos x-axis. Note order of x,y
std::cout << z << "\n";
z = fabs(u); //absolute value of u. Not to be
//confused with abs (integer equiv)
std::cout << z << "\n";
/* Many shorthand operands:
a = a+b; a+=b
a = a-b; a-=b
a = a*b; a*=b
a = a/b; a/=b
a = a%b; a%=b; if a and b are integers (a mod b)
a = a+1; a++; if a is an integer
a = a-1; a--; if a is an integer
*/
return 0;
}