//c code to find the vallue of sine and cosine
#include<stdio.h>
#include<conio.h>
#define pi 3.141593
int main(){
clrscr();
int i,n=15;
float x,sine,cosine,sine_term,cosine_term;
printf("enter angle in degree:\n");
scanf("%f",&x);
x*=pi/180;
sine=sine_term=x;
cosine=cosine_term=1;
for(i=1;i<n;i++){
sine_term*=(-1)*x*x/(2*i)/(2*i+1);
sine+=sine_term;
cosine_term*=(-1)*x*x/(2*i-1)/(2*i);
cosine+=cosine_term;
}
printf("sin(x)=%f\n",sine);
printf("cosine(x)=%f\n",cosine);
getch();
return 0;
}
No comments:
Post a Comment