Print Cos series

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include <math.h>
#include <stdio.h>
#include<conio.h>

const double PI = 3.14159265;

double MyCos(double x)
{
double sqx = x * x;
double cosineresult = 1;
double fact = 2;
int index = 2;
int term = 0;
double termfactor = 0;

for(term = 1; term < 20; term++)
{
termfactor = 0;
termfactor = sqx / fact;
if(term %2)
{
cosineresult = cosineresult - termfactor;
}
else
{
cosineresult = cosineresult + termfactor;
}
index++;
fact *= index;
index++;
fact *= index;
sqx *= (x*x);
}
return cosineresult;
}

int main()
{
double i = 0;
clrscr();
gotoxy(31,1);
printf("Sin Series");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
for(i = 0; i <= 360; i += 4.75)
{
printf("%.4lf = %.4lf\t%.4lf\n", i, cos(i * PI / 180), MyCos(i * PI / 180));
}
getch();

}

0 comments:

Post a Comment

 
Etutos © 2010-2011