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 MySin(double x)
{
double sqx = x * x * x;
double sineresult = x;
double fact = 2;
int index = 3;
int term = 0;
double termfactor = 0;
for(term = 1; term < 20; term++)
{
termfactor = 0;
termfactor = sqx / fact;
if(term % 2)
{
sineresult = sineresult - termfactor;
}
else
{
sineresult = sineresult + termfactor;
}
index++;
fact *= index;
index++;
fact *= index;
sqx *= (x*x);
}
return sineresult;
}
int main()
{
double i = 0,m,s;
clrscr();
gotoxy(31,1);
printf("Sin Series");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
printf("\nEnter the no. of elements for array:");
scanf("%d",&n);
printf("\nEnter the elements of the array:");
for(i = 0; i <= 360; i += 4.75)
{
s=sin(i * PI / 180);
m= MySin(i * PI / 180);
printf("%.4lf = %.4lf\t%.4lf\n", i,s,m);
}
return 0;
getch();
}
0 comments:
Post a Comment