1
0
Fork 0
mirror of https://codeberg.org/DansLeRuSH/c-plus-plus-exercises.git synced 2024-05-18 08:14:57 +00:00
c-plus-plus-exercises/EX08_nombre_premier.cpp

34 lines
580 B
C++

// Auteur : Franck ALBARET
#include <stdio.h>
#include <conio.h>
int main (void)
{
int Nbr=0;
int Cpt=0;
int Test=0;
puts("Entrez un nombre : \n");
scanf("%i",&Nbr);
Cpt=Nbr-1;
if (Cpt<1)
{
printf("Ce nombre n'est pas valide. \n");
return 0;
}
while (Cpt>1)
{
if (Nbr%Cpt!=0)
Cpt=Cpt-1;
else
{
Test=1;
Cpt=Cpt-1;
}
}
if (Test!=1)
printf("Le nombre %i est un nombre premier. \n",Nbr);
else
printf("Le nombre %i n'est pas un nombre premier. \n",Nbr);
return 0;
}