fin des tp
This commit is contained in:
BIN
DEV3.2/Recursiviote/Appel.class
Normal file
BIN
DEV3.2/Recursiviote/Appel.class
Normal file
Binary file not shown.
28
DEV3.2/Recursiviote/Appel.java
Normal file
28
DEV3.2/Recursiviote/Appel.java
Normal file
@@ -0,0 +1,28 @@
|
||||
public class Appel{
|
||||
public static int fact(int a, int indentation) {
|
||||
int i;
|
||||
for (i = 0; i < indentation; i++)
|
||||
System.out.print(" ");
|
||||
System.out.println("argument ="+a);
|
||||
if (a == 1) {
|
||||
return 1;
|
||||
} else {
|
||||
int res = a * fact(a-1, indentation+1);
|
||||
for (i = 0; i < indentation; i++)
|
||||
System.out.print(" ");
|
||||
System.out.println("resultat ="+res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] argv){
|
||||
if (argv.length < 1){
|
||||
System.err.println("manque un nombre pour le calcul");
|
||||
} else {
|
||||
int ind = 0;
|
||||
int n = Integer.parseInt(argv[argv.length-1]);
|
||||
int res = fact(n, ind);
|
||||
System.out.println(n+"! = "+res);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV3.2/Recursiviote/Fibonacci.class
Normal file
BIN
DEV3.2/Recursiviote/Fibonacci.class
Normal file
Binary file not shown.
38
DEV3.2/Recursiviote/Fibonacci.java
Normal file
38
DEV3.2/Recursiviote/Fibonacci.java
Normal file
@@ -0,0 +1,38 @@
|
||||
public class Fibonacci{
|
||||
public static int fibonacci(int x0, int x1, int val, int indentation) {
|
||||
int i;
|
||||
for (i = 0; i < indentation; i++)
|
||||
System.out.print(" ");
|
||||
System.out.println("u0 ="+x0+"u1 ="+x1);
|
||||
if (val == -2) {
|
||||
return x0;
|
||||
} else if (val == -1) {
|
||||
return x1;
|
||||
} else if (val == 0) {
|
||||
return x1;
|
||||
}else {
|
||||
int v = x0;
|
||||
x0 = x1;
|
||||
x1 = v + x1;
|
||||
val--;
|
||||
int res = fibonacci(x0, x1, val, indentation+1);
|
||||
for (i = 0; i < indentation; i++)
|
||||
System.out.print(" ");
|
||||
System.out.println("resultat ="+x1);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] argv){
|
||||
if (argv.length < 1){
|
||||
System.err.println("manque un nombre pour le calcul de la suite");
|
||||
} else {
|
||||
int x0 = 0;
|
||||
int x1 = 1;
|
||||
int ind = 0;
|
||||
int val = Integer.parseInt(argv[argv.length-1]) - 2;
|
||||
int res = fibonacci(x0, x1, val, ind);
|
||||
System.out.println("Fibonacci de "+(val+2)+"ième terme = "+res);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV3.2/Recursiviote/Tableaux.class
Normal file
BIN
DEV3.2/Recursiviote/Tableaux.class
Normal file
Binary file not shown.
63
DEV3.2/Recursiviote/Tableaux.java
Normal file
63
DEV3.2/Recursiviote/Tableaux.java
Normal file
@@ -0,0 +1,63 @@
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Tableaux{
|
||||
public static int[] remplir_tab(int val, String[] argv, int[] tab) {
|
||||
if (argv.length == val) {
|
||||
return tab;
|
||||
} else {
|
||||
tab[val] = Integer.parseInt(argv[val]);
|
||||
val++;
|
||||
return remplir_tab(val, argv, tab);
|
||||
}
|
||||
}
|
||||
|
||||
public static int pair_tab(int val, int pair, int[] tab) {
|
||||
if (tab.length == val) {
|
||||
return pair;
|
||||
} else {
|
||||
if (tab[val] % 2 == 0)
|
||||
pair++;
|
||||
val++;
|
||||
return pair_tab(val, pair, tab);
|
||||
}
|
||||
}
|
||||
|
||||
public static int max_tab(int val, int max, int[] tab) {
|
||||
if (tab.length == val) {
|
||||
return max;
|
||||
} else {
|
||||
if (tab[val] > max)
|
||||
max = tab[val];
|
||||
val++;
|
||||
return max_tab(val, max, tab);
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] inverse_tab(int val, int[] tab, int[] inv_tab) {
|
||||
if (tab.length == val) {
|
||||
return inv_tab;
|
||||
} else {
|
||||
inv_tab[val] = tab[tab.length-1-val];
|
||||
val++;
|
||||
return inverse_tab(val, tab, inv_tab);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] argv){
|
||||
if (argv.length < 1){
|
||||
System.err.println("il faut un nombre au minimum pour le tableau");
|
||||
} else {
|
||||
int[] tab = new int[argv.length];
|
||||
int[] inv_tab = new int[argv.length];
|
||||
int val = 0;
|
||||
int pair = 0;
|
||||
int max = 0;
|
||||
tab = remplir_tab(val, argv, tab);
|
||||
System.out.println(Arrays.toString(tab));
|
||||
System.out.println("nombre de pair ="+pair_tab(val, pair, tab));
|
||||
System.out.println("nombre le plus grand ="+max_tab(val, max, tab));
|
||||
inv_tab = inverse_tab(val, tab, inv_tab);
|
||||
System.out.println(Arrays.toString(inv_tab));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user