-
Notifications
You must be signed in to change notification settings - Fork 3
/
Printing-cos(x)-serese.c
62 lines (48 loc) · 1.23 KB
/
Printing-cos(x)-serese.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//Printing cos(x) serese:-
// 1-(x^2/2!)+(x^4/4!)-(x^6/6!)+(x^6/6!)+(x^6/6!)-(x^8/8!)...
#include<stdio.h>
int main()
{
int n,x;
double result;
double serese ( int ,int );
printf("Enter value of x : ");
scanf("%d",&x);
printf("Enter value of n : ");
scanf("%d",&n);
result = serese(x,n);
printf("Resilt is : %.3lf",result);
return 0;
}
double serese ( int x, int n )
{
int i,pow,fact,number;
int factorial( int );
int power( int , int );
double res = 0.0;
for ( i = 0 ; i <= n ; i++ )
{
number = 2*i ; // To bring odd number every time
pow = power(x,number);
fact = factorial(number);
if ( i%2 != 0 )
res = res + pow/(double)fact;
else
res = res - pow/(double)fact;
}
return res;
}
int power ( int x , int n)
{
int i,pow = 1;
for ( i = 1 ; i <= n ; i++ )
pow = pow*x;
return pow;
}
int factorial( int x)
{
int i,fact = 1;
for ( i = 1 ; i <= x ; i++ )
fact = fact*i;
return fact;
}