Skip to content
Snippets Groups Projects
Select Git revision
  • bf4583cd77ebacd8ad01cbc3dd6ee2bef1f8b024
  • master default protected
  • radhwan.hassine-master-patch-03421
  • radhwan.hassine-master-patch-79254
4 results

nb1er_refactored.c

Blame
  • 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;
    }