Program to calculate the cosine
series
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i, n;
float x, val, sum = 1, t = 1;
clrscr();
printf("Enter the value for x : ");
scanf("%f", &x);
printf("\nEnter the value for n : ");
scanf("%d", &n);
val = x;
x = x * 3.14159 / 180;
for(i = 1 ; i < n + 1 ; i++)
{
t = t * pow((double) (-1), (double) (2 * i - 1)) * x * x / (2 * i * (2 * i - 1));
sum = sum + t;
}
printf("\nCosine value of %f is : %8.4f", val, sum);
getch();
}
Output:
Enter the value for x : 60
Enter the value for n : 20
Cosine value of 60.000000 is : 0.5000
-
UpdatedDec 30, 2019
-
Views7,509
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order