Skip to content

Commit 96e85c4

Browse files
author
Hud
committed
GITA MASALA
1 parent ea113a5 commit 96e85c4

File tree

12 files changed

+115
-0
lines changed

12 files changed

+115
-0
lines changed
1.23 KB
Binary file not shown.
1.23 KB
Binary file not shown.
970 Bytes
Binary file not shown.
Binary file not shown.
1.27 KB
Binary file not shown.
1.05 KB
Binary file not shown.
1023 Bytes
Binary file not shown.

src/fori/For1.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package fori;
2+
3+
public class For1 {
4+
5+
public static void main(String[] args) {
6+
7+
solution(5, 10);
8+
}
9+
10+
public static void solution(int k, int n) {
11+
// k sonini n marta chop etilsin
12+
for (int i = 1; i <= n; i++) {
13+
System.out.print(String.format("%d: %d\n", i, k));
14+
}
15+
}
16+
}

src/fori/For10.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package fori;
2+
3+
public class For10 {
4+
5+
public static void main(String[] args) {
6+
solution(4);
7+
}
8+
9+
// s = 1 + 1/2 + 1/3 +1/4+...+ 1/n;
10+
public static void solution(int n) {
11+
double s = 0;
12+
for (int i = 1; i <= n; i++) {
13+
s += 1.0 / i;
14+
}
15+
System.out.println(s);
16+
}
17+
}

src/fori/For13.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fori;
2+
3+
public class For13 {
4+
5+
public static void main(String[] args) {
6+
solution(3);
7+
}
8+
9+
/**
10+
* @param n n>0 bo'lgan butun son
11+
* 1.1 - 1.2 + 1.3 - 1.4 + 1.5 + ... + n
12+
*/
13+
public static void solution(int n) {
14+
double sum = 0; // summani hisoblash uchun
15+
int ishora = 1; // 1, -1
16+
for (double i = 1.1; i <= n; i += 0.1) {
17+
// i: 1.1, 1.2, 1.3, 1.4, 1.5... n
18+
sum += ishora * i; // -1 * 1.2
19+
ishora *= -1; // -1
20+
}
21+
22+
System.out.println(sum);
23+
}
24+
}

src/fori/For20.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package fori;
2+
3+
import java.util.Scanner;
4+
5+
public class For20 {
6+
7+
public static void main(String[] args) {
8+
Scanner scanner = new Scanner(System.in);
9+
int n = scanner.nextInt();
10+
long s = solution(n); // 1!+2!+..+
11+
System.out.println(s);
12+
}
13+
14+
// a + b
15+
// a,b => -10^100 .. 10^100
16+
17+
// 5! = 1*2*3*4*5
18+
// 5! = 5*4! = 5*24=120
19+
// 4! = 4*3! = 4*6 = 24
20+
// 3! = 3*2! = 3*2=6
21+
// 2! = 2*1! = 2
22+
// 1! = 1
23+
24+
// sum = 1!+2!+3!+4!+...+n!
25+
public static long solution(long n) {
26+
long s = 0;
27+
long factorial = 1;
28+
for (int i = 1; i <= n; i++) {
29+
factorial *= i;
30+
s += factorial;
31+
}
32+
return s;
33+
}
34+
}

src/fori/For22.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fori;
2+
3+
public class For22 {
4+
public static void main(String[] args) {
5+
double result = solution(3,0.5);
6+
System.out.println(result);
7+
8+
// 1 + 0.5/1! + 0.5^2/2! + 0.5^3/3!
9+
}
10+
11+
public static double solution(int n, double x) {
12+
double sum = 1; // sum + x^i/i! + x^2/2! + x^3/3! + ...
13+
int factorial = 1;
14+
double pow = x;
15+
for (int i = 1; i <= n; i++) {
16+
// pow = x^i
17+
// factorial = i!
18+
sum += pow / factorial;
19+
factorial *= i;
20+
pow *= x; // x * x
21+
}
22+
return sum;
23+
}
24+
}

0 commit comments

Comments
 (0)