You are on page 1of 3

#include <iostream>

#define PI 3.141592653
using namespace std;
int fact(int n) {
int f = 1;
for(int i = 2; i <= n; i++)
{f *= i;}
return f;}
double power(double x, int y) {
double p = 1;
for(int i = 0; i < y; i++) {
p *= x;}
return p;}
double my_sin(int deg) {
deg %= 360;
float rad = deg * PI / 180;
float sin_v = 0;
int terms = 6;
for(int i = 0; i < terms; i++) {
sin_v += power(-1, i) * power(rad, 2 * i + 1) / fact(2 * i + 1);}
return sin_v;}
double my_cos(int deg) {
deg %= 360;
float rad = deg * PI / 180;
float cos_v = 0;
int terms = 6;
for(int i = 0; i < terms; i++) {
cos_v += power(-1, i) * power(rad, 2 * i) / fact(2 * i);}
return cos_v;}
double my_exp(int x) {
double exp_v = 0;
int terms = 13;
for(int i = 0; i < terms; i++) {
exp_v += power((double)x, i) / fact(i);}
return exp_v;}
int main() {
cout << "Name: Ayush \nRoll no. 3554" << endl;
char chk = 'y';
while(chk == 'y' || chk == 'Y') {
cout << "MENU:\n1.Sin(x)\n2.Cos(x)\n3.e^(x)\nEnter Your Choice: ";
int opt;
cin >> opt;
int x;
switch(opt) {
case 1:
cout << "Enter x (degrees): ";
cin >> x;
cout << "Sin(" << x << "): " << my_sin(x) << endl;
break;
case 2:
cout << "Enter x (degrees): ";
cin >> x;
cout << "Cos(" << x << "): " << my_cos(x) << endl;
break;
case 3:
cout << "Enter x: ";
cin >> x;
cout << "e^(" << x << "): " << my_exp(x) << endl;
break;
default:
cout << "Enter Valid Choice!!!!!\n" << endl;
break;
}
cout << "Would you like to perform again? (Y/N): ";
cin >> chk;}
    return 0;}

You might also like