/*Sum of infinite series with specified accuracy*/
#include<stdio.h>
#include<math.h>
int main()
{
int i;
float x, sum, t, x1;
printf("Value of x in degrees:");
scanf("%f",&x);
x1=x;
x=x*3.14159/180;
sum=x;
t=x;
i=1;
label: i=i+2;
t=(-t)*x*x/(i*(i-1));
if (fabs (t)>0.00001)
{
sum=sum+t;
goto label;
}
else
printf("sin(%f)=%f\n",x1,sum);
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int i;
float x, sum, t, x1;
printf("Value of x in degrees:");
scanf("%f",&x);
x1=x;
x=x*3.14159/180;
sum=x;
t=x;
i=1;
label: i=i+2;
t=(-t)*x*x/(i*(i-1));
if (fabs (t)>0.00001)
{
sum=sum+t;
goto label;
}
else
printf("sin(%f)=%f\n",x1,sum);
return(0);
}
Comments
Post a Comment