#include #include int factorial(int n) { if (n == 0) { return 1; } else { return n*factorial(n-1); } } int main(void) { /* variables declaration */ long double x=0; long double sinval = 0,cosval = 0; int n,i,sinsign,cossign; char print_st[20]; char c1 = 1; /* Get input x in radians */ printf("Enter cos/sin: "); scanf("%s",print_st); switch(print_st[0]) { case 'c': printf("String = cos\n"); break; case 's': printf("String = sin\n"); break; default: printf("String invalid\n"); break; } printf("%s of which x :",print_st); scanf("%Lf",&x); n=0; i=0; sinsign=1; cossign=1; while(n<10) { if (n%2 == 1) { sinval = sinval + sinsign*pow(x,n)/factorial(n); sinsign=sinsign*(-1); } else { cosval = cosval + cossign*pow(x,n)/factorial(n); cossign=cossign*(-1); } n++; } /* Print sin,cos values */ switch(print_st[0]) { case 'c': printf("Approximately, Cos(%.2Lf) = %Lf\n",x,cosval); break; case 's': printf("Approximately, Sin(%.2Lf) = %Lf\n",x,sinval); break; default: printf("Approximately, Sin(%.2Lf) = %Lf, Cos(%.2Lf) = %Lf\n",x,sinval,x,cosval); break; } return 0; }