Question 1: [10 points] Write a computer program that calculates the approximate
ID: 3723925 • Letter: Q
Question
Question 1: [10 points] Write a computer program that calculates the approximate value of sin(x) using the Maclaurin series approximation: 3 .5 .7 up to 8 significant figures. Use ,-0.5 × 102-n % in order to continue until the Ea falls below this criteria Run your program for x-/3 and-/4, and tabulate the approximate values of sin(r), the true and approximate percent relative errors for various terms that are taken for the series. In the table, show the approximate results for more than 8 significant figures rounded for different number of terms to show that the final approximate is accurate to at least 8 significant figuresExplanation / Answer
PROGRAMME :
PROCEDURE 1 :
#include<stdio.h>
int main()
{
int x,n,t=1,i,j;
double num,sum=0.0,r;
long int deno;
printf(" INPUT:");
printf(" ------");
printf(" Enter the value for x: ");
scanf("%d",&x);
printf(" Enter the value for n: ");
scanf("%d",&n);
printf(" OUTPUT:");
printf(" -------");
r=x*(3.14/180.0);
printf(" The radius value for the given x value is: %lf",r);
for(i=1;i<=n;i+=2)
{
num=1.0;
deno=1;
for(j=1;j<=i;j++)
{
num=num*r;
deno=deno*j;
}
sum=sum+num/deno*t;
t=t*-1;
printf(" The value for sin %d is: %.11f",x,sum);
}
printf(" ");
return 0;
}
PROCEDURE 2 :
#include<stdio.h>
float srs(float x,int i);
float term(float x,int i);
int main()
{
float x,y;
int i;
printf("enter the value of x ");
scanf("%f",&x);
i=1;
y=srs(x,i);
printf("the sum is equals to %f",y);
return 0;
}
float srs(float x,int i)
{
float sum=0.0;
float t;
t= term(x,i);
if(i%2==0&&t>(-.000001))
{
return 0;
}
else if(i%2!=0&&t<(.000001))
{
return 0;
}
else
{
sum=t+ srs(x,i+1);
}
return sum;
}
float term(float x,int i)
{
float tn;
int h;
tn=x;
for(h=2;h<2*i;h++)
{
tn= (x*tn)/h;
}
if(i%2==0)
{
tn= tn*(-1.0);
return tn;
}
else
{
return tn;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.