Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double radians(double degrees) // converts degrees to radians
- {
- double radians;
- double const pi = 3.14159265358979323846;
- radians = (pi / 180) * degrees;
- return radians;
- }
- double fact(int x) //calculates the factorial
- {
- double fact = 1;
- for (; x >= 1; x--) {
- fact = x * fact;
- }
- return fact;
- }
- double sin(double x) {
- double sum = 0;
- int i = 1;
- int sign = 1;
- double term;
- do {
- term = pow(x, i) / fact(i);
- sum += sign * term;
- sign = -sign;
- i += 2;
- } while (term > 0.000001);
- return sum;
- }
- int main() {
- double n, output;
- cout << "Please enter the value in degrees: ";
- cin >> n;
- n = radians(n);
- cout << "The angle in radians is: " << n << endl;
- output = sin(n);
- cout << "The sinus is: " << output << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement