-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFun42.java
More file actions
33 lines (27 loc) · 742 Bytes
/
Fun42.java
File metadata and controls
33 lines (27 loc) · 742 Bytes
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
package fun;
public class Fun42 {
public static void main(String[] args) {
System.out.println(Cos1(5,10));
}
public static double Cos1(double x, double e){
double sum = 1;
double surat, maxraj;
int ishora = -1;
// n=10
// 2 4 6 8 10
for (int i = 1; i <= e; i++) {
surat = Math.pow(x, 2 * i); // x^2
maxraj = foctarial(2 * i); // 2!
sum += ishora * surat / maxraj;
ishora *= -1;//
}
return sum;
}
public static int foctarial(int n){
int f=1;
for (int i = 1; i <=n; i++) {
f*=i;
}
return f;
}
}