18. Write a program to compute Cosine series i.e.
Cos(x)= 1 – x2/2! + x4/4! – x6/6! + …xn/n!
Algorithm:
Input
1. x //x=2
2. n //n=3
Output
1. cx // cosine series
Method:
1. start
2. Read x
3. Read n
4. //logic
cx=1;
j=2;
for(i=2;i<=n;i++)
begin
fact=1;
for(k=j;k>=1;k--)
begin
fact=fact*k
end
if(i%2==0)
{
cx=cx-pow(x,j)/fact;
}
else
{
cx=cx+pow(x,j)/fact;
}
j=j+2;
end
loop end
5.print cx
6.stop
Cos(x)= 1 – x2/2! + x4/4! – x6/6! + …xn/n!
Algorithm:
Input
1. x //x=2
2. n //n=3
Output
1. cx // cosine series
Method:
1. start
2. Read x
3. Read n
4. //logic
cx=1;
j=2;
for(i=2;i<=n;i++)
begin
fact=1;
for(k=j;k>=1;k--)
begin
fact=fact*k
end
if(i%2==0)
{
cx=cx-pow(x,j)/fact;
}
else
{
cx=cx+pow(x,j)/fact;
}
j=j+2;
end
loop end
5.print cx
6.stop
No comments:
Post a Comment