mirror of
https://codeberg.org/DansLeRuSH/c-plus-plus-exercises.git
synced 2024-11-24 04:08:08 +00:00
Is it a prime number ?
This commit is contained in:
parent
27b881a5bb
commit
f122bb0895
1 changed files with 33 additions and 0 deletions
33
EX08_nombre_premier.cpp
Normal file
33
EX08_nombre_premier.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
// 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;
|
||||
}
|
Loading…
Reference in a new issue