oups sorry ds le prog
[/cpp]#include <stdio.h>
/* ------------------------------------------------------------------------ */
void PrintDescription(void)
/* Affiche des informations concernant le crible d'Eratosthene sur la */
/* sortie standard. */
{
printf( "------------------------------------------------------\n" );
printf( "Crible d'Eratosthene\n" );
printf( "------------------------------------------------------\n" );
printf( "Cette methode permet d'obtenir la liste des nombres\n" );
printf( "premiers inferieurs a n.\n" );
printf( "------------------------------------------------------\n" );
}
void tab(n)
{ int i=0,a=2;
printf("\n" );
int B[n];
printf("premier tableau, ts les nombres\n" );
while (a<=n) {B[i]=a; ;printf( "%d ", B[i]); a=a+1;i=i+1;};
}
void tri(n)
{ int b, cpt=0,a;
printf("\n" );
printf("\n" );
int B[n];
printf("deuxieme tableau, rien que les nombres premiers\n" );
for(a=2;a<=n;a++) {B[a]=a;}
for (a=2;a<=n;a++)
{if (B[a]!=0) {for(b=a+1;b<=n;b++)
{if ((B[b]!=0) & (B[b]%a==0)) {B[b]=0;}}
}
}
for (a=2;a<=n;a++) {if (B[a]>0) {cpt++;printf("%d ", B[a]);}
;}
printf("\n" );
if ( cpt<=1) {printf("\n%d nombre premier au total\n", cpt);};
if ( cpt>1) {printf("\n%d nombres premiers au total\n", cpt);};
}
int main()
{int choix, n;
PrintDescription();
while (1)
{printf("\n1) Crible\n2) Quit\n" );
printf("\n" );
scanf("%d", &choix);
switch(choix) { case 1 : printf("\nchoix n = ?\n " );
printf("\n" );
scanf("%d", &n);
if (n<2) {printf("\n" );printf("He oh quel est l'interet de chercher les nombres premiers inferieurs a 2?\n" );
break;};
tab(n), tri(n);break;
default : printf("\n" );printf("Au revoir\n" );return 0;
}
}
}
[cpp]