C program to find the value of cos(x)

Write a 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. Read more about C Programming Language.

* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*                                  Happy Coding

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

void main()
 int  n, x1;
 float  acc, term, den, x, cosx=0, cosval;


 printf("Enter the value of x (in degrees)n");

 x1 = x;

 /* Converting degrees to radians*/

 x = x*(3.142/180.0);
 cosval = cos(x);

 printf("Enter the accuary for the resultn");
 scanf("%f", &acc);
 term = 1;
 cosx = term;
 n = 1;

  den = 2*n*(2*n-1);
  term = -term * x * x / den;
  cosx = cosx + term;
  n = n + 1;
 } while(acc <= fabs(cosval - cosx));

 printf("Sum of the cosine series       = %fn", cosx);
 printf("Using Library function cos(%d) = %fn", x1,cos(x));
}         /*End of main() */
Read more Similar C Programs
C Basic

Search Algorithms.

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

Leave a Reply