/* To find sin(x) */
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f0(x) sin(x)
#define f1(x) cos(x)
#define f2(x) -sin(x)
#define f3(x) -cos(x)
#define f4(x) sin(x)
void main()
{
float t,x,h,v,i=0,ea=100;
clrscr();
puts("Enter value of x & h to find sin(x)");
scanf("%f %f",&x,&h);
x=x*3.14231/180;
h=h*3.14231/180;
puts("------------------------------------------------");
puts("Iter. ln(x+h) \tEa");
puts("------------------------------------------------");
v=f0(x);
printf("%2.0f\t%f\t%f",i++,v,ea);
t=v;
v=v+h*f1(x);
ea=(v-t)*100/v;
printf("\n%2.0f\t%f\t%f",i++,v,ea);
t=v;
v=v+h*h*f2(x)/2;
ea=(v-t)*100/v;
printf("\n%2.0f\t%f\t%f",i++,v,ea);
t=v;
v=v+h*h*h*f3(x)/(3*2);
ea=(v-t)*100/v;
printf("\n%2.0f\t%f\t%f",i++,v,ea);
t=v;
v=v+h*h*h*h*f4(x)/(4*3*2);
ea=(v-t)*100/v;
printf("\n%2.0f\t%f\t%f",i++,v,ea);
puts("\n-----------------------------------------------");
getch();
}
Output of Program:-
Enter value of x & h to find sin(x)
44 1
------------------------------------------------
Iter. sin(x+h) Ea
------------------------------------------------
0 0.694658 100.000000
1 0.707213 1.775254
2 0.707107 -0.014962
3 0.707106 -0.000093
4 0.707106 0.000000
------------------------------------------------
No comments:
Post a Comment