0% found this document useful (0 votes)
103 views

C Program For COS Series

This C program calculates an approximation of the cosine of an angle x by summing the terms of its Taylor series expansion. The user inputs the angle x in degrees and the number of terms n. The program converts x to radians, initializes the sum to 1 and a term t to 1, then uses a for loop to calculate each term of the series from 1 to n, multiplying t by -1, x squared, and dividing by the factorial of the term number. It prints the final sum as the approximation of cos(x).

Uploaded by

Pawan S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

C Program For COS Series

This C program calculates an approximation of the cosine of an angle x by summing the terms of its Taylor series expansion. The user inputs the angle x in degrees and the number of terms n. The program converts x to radians, initializes the sum to 1 and a term t to 1, then uses a for loop to calculate each term of the series from 1 to n, multiplying t by -1, x squared, and dividing by the factorial of the term number. It prints the final sum as the approximation of cos(x).

Uploaded by

Pawan S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

/* C Program for evaluating COS series */

#include<stdio.h>
void main()
{
int i, n;
float x, sum=1, t=1;
printf(" Enter the value for x : ");
scanf("%f",&x);
printf(" Enter the value for n : ");
scanf("%d",&n);
x=x*3.14159/180;
/* Loop to calculate the value of Cosine */
for(i=1;i<=n;i++)
{
t=t*(-1)*x*x/(2*i*(2*i-1));
sum=sum+t;
}
printf(" The value of Cos(%f) is : %.4f", x, sum);

You might also like