C program to find the sum of cos(x) series

by Nideesh C on April 12, 2011 · 1 comment

in C Programming




/* C program to find the sum of cos(x) series */

#include  < stdio.h>
#include  <math.h>

void main()
{
int n,x1,i,j;
float x,sign,cosx,fact;

printf(“Enter the number of the terms in aseries\n”);
scanf(“%d”,&n);

printf(“Enter the value of x(in degrees)\n”);
scanf(“%f”,&x);

x1=x;

x=x*(3.142/180.0); /* Degrees to radians*/

cosx=1;

sign=-1;

for(i=2;i<=n;i=i+2)
{
fact=1;

for(j=1;j<=i;j++)
{
fact=fact*j;
}

cosx=cosx+(pow(x,i)/fact)*sign;
sign=sign*(-1);
}

printf(“Sum of the cosine series = %7.2f\n”,cosx);
printf(“The value of cos(%d) using library function = %f\n”,x1,cos(x));

} /*End of main() */

/*——————————————————–
Output
Enter the number of the terms in aseries
5
Enter the value of x(in degrees)
60
Sum of the cosine series = 0.50
The value of cos(60) using library function = 0.499882
——————————————————–*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to find the value of cos(x) using the series up to the given accuracy (without using user defined function) Also print cos(x) using library function.
  2. C program to find the value of sin(x) using the series up to the given accuracy (without using user defined function) Also print sin(x) using library function.
  3. C program to read a matrix A (MxN) and to find the following using functions a) Sum of the elements of each row b) Sum of the elements of each column c) Find the sum of all the elements of the matrix Output the computed results with suitable headings
  4. C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
  5. C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings

Leave a Comment

{ 1 trackback }

Previous post:

Next post: