Select Git revision
nb1er_refactored.c
Forked from
algorithmique / cours
Source project has a limited visibility.
nb1er_refactored.c 564 B
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
// fonction testant si un nombre est 1er
bool is_prime(int nb);
void main() {
int nb = 1;
printf("Entrez un nombre: ");
scanf("%d",&nb);
if (is_prime(nb)) {
printf("Le nombre %d est premier\n",nb);
} else {
printf("Le nombre %d n'est pas premier\n",nb);
}
}
bool is_prime(int nb) {
bool premier = true;
for (int div=2;div<=sqrt(nb);div++) {
if (nb%div == 0) {
premier = false;
break;
}
}
return premier;
}