/*to find summation of a sine series with specific
accuracy*/
#include<stdio.h>
#include<math.h>
void
main()
{
float
x,sum,t;
int
i;
printf("enter
the value of x in degrees:");
scanf("%f",&x);
x=x*(3.1415/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("\n sin(x)=%f\n",sum);
}
Result1:
enter the value of x in degrees:90
sin(x)=1.000004
Press any key to continue
Result2:
enter the value of x in degrees:47
sin(x)=0.731337
Press any key to continue
/*to find summation of a cosine series with specific
accuracy*/
#include<stdio.h>
#include<math.h>
void
main()
{
float
x,sum,t;
int
i;
printf("enter
the value of x in degrees:");
scanf("%f",&x);
x=x*(3.1415/180);
sum=1;
t=1;
i=0;
label:i=i+2;
t=((-t)*x*x)/(i*(i-1));
if(fabs(t)>0.00001)
{
sum=sum+t;
goto label;
}
else
printf("\n cos(x)=%f\n",sum);
}
RESULT1:
enter the value of x in degrees:0
cos(x)=1.000000
Press any key to continue
RESULT2:
enter the value of x in degrees:47
cos(x)=0.682011
Press any key to continue
/*to find summation of a exponential series with
specific accuracy*/
#include<stdio.h>
#include<math.h>
void
main()
{
float
x,sum,t;
int
i;
printf("enter
the value of x:");
scanf("%f",&x);
sum=1;
t=1;
i=0;
label:i=i++;
t=((t)*x)/(i);
if(fabs(t)>0.00001)
{
sum=sum+t;
goto label;
}
else
printf("\n exp(x)=%f\n",sum);
}
Result1:
enter the value of x:0
exp(x)=1.000000
Press any key to continue
Result2:
enter the value of x:5
exp(x)=148.413162
Press any key to continue
No comments:
Post a Comment
Thanks for comment.