I want to write a pogram which will calculate cosine series.

But I am not get the value like cos() function of math.h

Could you tell me why it is happening and any error in my code or any step mistake ?????

Code:float cos1(float x) { int i,fact=1; float sum,term; sum=1.0; term=1.0; for(i=1;i<5;i++) { term=term*x*x; term=term*(-1); fact=factorial(2*i); sum=sum+(term/fact); } return(sum); } int factorial(int x) { int fact; if(x==1) return(1); else fact=x*factorial(x-1); return(fact); } also in the place of for loop i am using do while loop but result is same float cos1(float x) { int i,fact=1; float sum,term; sum=1.0; term=1.0; i=1; do { term=term*x*x; term=term*(-1); fact=factorial(2*i); sum=sum+(term/fact); i++; } while(term>0.00001) return(sum); }