voila je dois rechercher (recherche dichotomique) où inserer (trouver les indices) une valeur non présente dans le tableau! avant toute chose je suis un débutant (snif) mais j'ai tester plusieurs fois sur papier je comprend pas pourquoi mon prog ne fonctionne pas!
si quelqu'un trouve mon ou mes erreurs...
Merci à tous!
le voici correctement indenté (enfin je pense)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
63
64 program rechercheinconnu; Const N=10; var Tab : array [0..N] of integer; Nb, Debut, Fin, i, Nbmax, milieu : integer; Begin repeat writeln ('combien voulez entrez de chiffre au maximum?'); readln (Nbmax); until (Nbmax<10); for i:=0 to (Nbmax-1) do begin writeln ('entrez un chiffre'); readln (tab[i]); end; writeln ('quelle valeur voulez vous inserer?'); readln (Nb); Debut := 0; Fin := Nbmax; i := ((debut+fin) div 2); if ((Nb>tab[0]) and (Nb<tab[Nbmax])) then begin while (Nb<>Tab[i]) and (tab[Nbmax]<>Nb) and (fin<>(debut+1)) do begin If (tab[i]>Nb) then begin Fin := (i); end else begin debut := (i); end; i := ((debut+fin) div 2); end; if (tab[i] = Nb) or (Fin<>(debut+1)) then begin writeln ('a lindice ', i); end else begin writeln ('entre ', debut, 'et ', fin); end; end else begin if (Nb<=tab[0]) then begin writeln ('a la case 0'); end else begin writeln ('a la case', Nbmax); end; end; end.
prog2.pas
Partager