Saturday, December 4, 2010

Sine Table

#include<stdio.h>
#include<conio.h>
#define pi 3.14159262
int main()
{
float term,dr,dc,d,r;
float sintable[19][5];
int n,x,y;
clrscr();
x=0;
dr=dc=0;
while(x<19)
{
y=0;
while(y<5)
{
if((x==0)&&(y!=0))
{
sintable[x][y]=dc;
dc+=5;
printf("%0.0f\t",sintable[x][y]);
}
else if((y==0)&&(x!=0))
{
sintable[x][y]=dr;
dr+=20;
printf("%0.0f\t",sintable[x][y]);
}
else if((x==0)&&(y==0))
printf("DEGREE\t");
else
{
d=sintable[x][0]+sintable[0][y];
r=d*pi/180;
n=1;
sintable[x][y]=term=r;
while(n<100)
{
term*=((-1)*r*r/((n+1)*(n+2)));
sintable[x][y]+=term;
n+=2;
}
printf("%0.4f\t",sintable[x][y]);
}
y++;
}
printf("\n");
x++;
}
printf("\n$ No of terms we calculate: 51 $\n");
getch();
return 0;
}

No comments:

Post a Comment