Write a function to find value of sin(x) using Expansion Series given below: Code: sin(x) = x - x^3/3! + x^5/5! - x^7/7!...... answer- #include <stdio.h> #include <math.h> int factorial(int a) { int i,k; for(i=a;i>0;i--) { k=k*i; } return k; } float power(float a,float b) { float i,j; j=1; for(i=1;i<=b;i++) { j=j*a; } return j; } int main() { float i,x,y,term,sum=0; printf("Enter the variable x\n"); printf("Enter the prescribed precision\n"); scanf("%f%f",&x,&y); for(i=1;(term/sum)*100<=y;i++) { term=power(-1,(i+1))*power(x,(2*i-1))/factorial((2*i-1)); sum+=term; } printf("sin(%f)=%f",x,sum); return 0; }
In for(i=1;(term/sum)*100<=y;i++) you have done like(term/sum) which is 0/0 which is not valid mathematical operation.