tp1 exo8
This commit is contained in:
parent
250a1552c0
commit
323dd55be4
36
tp1/exo8.c
Normal file
36
tp1/exo8.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int is_prime(uint a) {
|
||||||
|
uint i = 2;
|
||||||
|
while (i * i <= a) {
|
||||||
|
if (a % i == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int f(int a) { return is_prime(abs(a)); }
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int a = 1103;
|
||||||
|
int b = 21;
|
||||||
|
int c = -23;
|
||||||
|
if (f(a)) {
|
||||||
|
printf("%d est premier\n", a);
|
||||||
|
} else {
|
||||||
|
printf("%d n'est pas premier\n", a);
|
||||||
|
}
|
||||||
|
if (f(b)) {
|
||||||
|
printf("%d est premier\n", b);
|
||||||
|
} else {
|
||||||
|
printf("%d n'est pas premier\n", b);
|
||||||
|
}
|
||||||
|
if (f(c)) {
|
||||||
|
printf("%d est premier\n", c);
|
||||||
|
} else {
|
||||||
|
printf("%d n'est pas premier\n", c);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user