This commit is contained in:
2026-03-15 20:40:00 +05:00
parent 06a34a1406
commit 775b21a9c4
5 changed files with 100 additions and 0 deletions

32
lr9/task_1/e5.java Normal file
View File

@@ -0,0 +1,32 @@
import java.util.Scanner;
class Main {
public static void main(String[] args) {
int result = fact(5);
System.out.println("Результат: " + result);
}
public static int fact(int n) {
System.out.println("Вход в fact(" + n + ")");
if (n == 0) {
System.out.println("fact(0) -> 0");
return 0;
}
else if (n == 1) {
System.out.println("fact(1) -> 1");
return 1;
}
else {
int a = fact(n - 2);
int b = fact(n - 1);
int result = a + b;
System.out.println("fact(" + n + ") = fact(" + (n-2) + ") + fact(" + (n-1) + ") = " + result);
return result;
}
}
}