Last change
on this file since 107 was
102,
checked in by rosiere, 16 years ago
|
Previous commit with new files :P
|
-
Property svn:keywords set to
Id
|
File size:
1.8 KB
|
Line | |
---|
1 | #include "func_factoriel.h" |
---|
2 | #include "func_math.h" |
---|
3 | #include "func_io.h" |
---|
4 | |
---|
5 | //-----[ Factoriel ]------------------------------------------------------- |
---|
6 | |
---|
7 | unsigned int factoriel_recursif (unsigned int x) |
---|
8 | { |
---|
9 | if ( x <= 1) |
---|
10 | return 1; |
---|
11 | |
---|
12 | return (mul_soft (x , factoriel_recursif (x-1) ) ); |
---|
13 | } |
---|
14 | |
---|
15 | unsigned int factoriel_iteratif (unsigned int x) |
---|
16 | { |
---|
17 | unsigned int res= 1; |
---|
18 | |
---|
19 | while (x > 1) |
---|
20 | { |
---|
21 | res = mul_soft(res,x); |
---|
22 | x --; |
---|
23 | } |
---|
24 | return res; |
---|
25 | } |
---|
26 | |
---|
27 | //------------------------------------------------------------------------- |
---|
28 | //-----[ Test ]------------------------------------------------------------ |
---|
29 | //------------------------------------------------------------------------- |
---|
30 | |
---|
31 | void test_factoriel_iteratif (int x) |
---|
32 | { |
---|
33 | int x_max = 12; |
---|
34 | int wait [x_max+1]; |
---|
35 | |
---|
36 | wait[0] = 1; // 1 |
---|
37 | wait[1] = 1; // 1 |
---|
38 | wait[2] = 2; // 2 |
---|
39 | wait[3] = 6; // 6 |
---|
40 | wait[4] = 24; // 18 |
---|
41 | wait[5] = 120; // 78 |
---|
42 | wait[6] = 720; // 2d0 |
---|
43 | wait[7] = 5040; // 13b0 |
---|
44 | wait[8] = 40320; // 9d80 |
---|
45 | wait[9] = 362880; // 58980 |
---|
46 | wait[10] = 3628800; // 375f00 |
---|
47 | wait[11] = 39916800; // 2611500 |
---|
48 | wait[12] = 479001600; // 1c8cfc00 |
---|
49 | |
---|
50 | for (int i = 0; i <= ((x<x_max)?x:x_max); i ++) |
---|
51 | if (factoriel_iteratif (i) != wait[i]) quit(i+1); |
---|
52 | } |
---|
53 | |
---|
54 | void test_factoriel_recursif (int x) |
---|
55 | { |
---|
56 | int x_max = 12; |
---|
57 | int wait [x_max+1]; |
---|
58 | |
---|
59 | wait[0] = 1; // 1 |
---|
60 | wait[1] = 1; // 1 |
---|
61 | wait[2] = 2; // 2 |
---|
62 | wait[3] = 6; // 6 |
---|
63 | wait[4] = 24; // 18 |
---|
64 | wait[5] = 120; // 78 |
---|
65 | wait[6] = 720; // 2d0 |
---|
66 | wait[7] = 5040; // 13b0 |
---|
67 | wait[8] = 40320; // 9d80 |
---|
68 | wait[9] = 362880; // 58980 |
---|
69 | wait[10] = 3628800; // 375f00 |
---|
70 | wait[11] = 39916800; // 2611500 |
---|
71 | wait[12] = 479001600; // 1c8cfc00 |
---|
72 | |
---|
73 | for (int i = 0; i <= ((x<x_max)?x:x_max); i ++) |
---|
74 | if (factoriel_recursif (i) != wait[i]) quit(i+1); |
---|
75 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.