PROCEDURE:-
CODE:-
#include<stdio.h>
void main()
{
int i=1,n;
float sum,t,x,y;
printf(“enter the number of terms and degrees”)
scanf(“%d %f”,&n,&y);
x=y*3.142/180;
sum=x;
t=x;
while(i<n)
{
t=((-t)*x*x)/((2*i)*(2*i+1));
sum=sum+t;
i++;
}
printf(“ cos(%f)=%f”,y,sum);
}
Input:- enter the number of terms and degrees 10 60
Output:-cos(60)=0.499999
- input values for degrees x and the number of terms to be added n
- convert the given degrees to radians
- substitute in the series to find the sum
- print the sum
CODE:-
#include<stdio.h>
void main()
{
int i=1,n;
float sum,t,x,y;
printf(“enter the number of terms and degrees”)
scanf(“%d %f”,&n,&y);
x=y*3.142/180;
sum=x;
t=x;
while(i<n)
{
t=((-t)*x*x)/((2*i)*(2*i+1));
sum=sum+t;
i++;
}
printf(“ cos(%f)=%f”,y,sum);
}
Input:- enter the number of terms and degrees 10 60
Output:-cos(60)=0.499999
Comments
Post a Comment