Last change
on this file was
81,
checked in by rosiere, 17 years ago
|
- Finish Environment (and test)
- Continue predictor_unit
- Add external tools
- svn keyword "Id" set
|
-
Property svn:keywords set to
Id
|
File size:
575 bytes
|
Line | |
---|
1 | #include "func_math.h" |
---|
2 | #include "func_premier.h" |
---|
3 | |
---|
4 | //-----[ Premier ]--------------------------------------------------------- |
---|
5 | |
---|
6 | unsigned int premier(unsigned int x) |
---|
7 | { |
---|
8 | unsigned int it; |
---|
9 | |
---|
10 | if (x <= 0) |
---|
11 | return 0; |
---|
12 | |
---|
13 | if (x <= 2) |
---|
14 | return 1; |
---|
15 | |
---|
16 | for(it=2; it <= (x/2); it++) |
---|
17 | if (modulo(x,it) == 0) |
---|
18 | return 0; |
---|
19 | |
---|
20 | return 1; |
---|
21 | } |
---|
22 | |
---|
23 | unsigned int n_premier(unsigned int nieme_premier) |
---|
24 | { |
---|
25 | unsigned int nb_find = 0; |
---|
26 | unsigned int res = 1; |
---|
27 | while (nb_find < nieme_premier) |
---|
28 | { |
---|
29 | res ++; |
---|
30 | if (premier(res) == 1) |
---|
31 | nb_find ++; |
---|
32 | } |
---|
33 | return res; |
---|
34 | } |
---|
35 | |
---|
Note: See
TracBrowser
for help on using the repository browser.