/* CALCULATING THE VALUE OF SIN(x) AND COS(x)USING FORMULA */
#include #include #include
float sin_x(float ,int ); float cos_x(float ,int ); float power(float ,int ); float fact (int);
void main() { int k=0,n; float x; clrscr(); printf("\n Enter the value of n:\t"); scanf("%d",&n); printf("\n The table is\n\n x(in degree) sinx\t\t cosx\n"); printf(" -------------------------------------\n");
while(k<=90) /*The value of k is in degree*/ { x=k; x=(x*(4*atan(1)))/180; printf(" %4d\t\t%0.4f\t\t%0.4f\n",k,sin_x(x,n),cos_x(x,n)); k+=15; } printf(" -------------------------------------\n"); getch(); }
float sin_x(float x,int n) { float sum=0,f; int i; for(i=1;i<=n;i++) { f=fact(2*i-1); sum+=power(-1,i+1)*power(x,2*i-1)/f; } if(sum<0) sum=-sum; return(sum); } float cos_x(float x,int n) { int i; float f,sum=0; for(i=1;i<=n;i++) { f=fact(2*i-2); sum+=power(-1,i+1)*power(x,2*i-2)/f; } if(sum<0) sum=-sum; return(sum); } float fact(int n) { if(n==0 || n==1) return 1; else return n*fact(n-1); } float power(float x,int n) { int i; float k; k=x; if(!n) return (1); else { for(i=1;i k=k*x; return (k); } }
|
| Author: PANKAJ KUMAR MISHRA | Member Level: Silver | Revenue Score:  |
this is awesome program,i try it and its work propely.
|