/* Exercice 1: Solution avec Next(p) 15/10/02 http://www.Software-DS.com */ #include <stdio.h> /* prototypes */ int premier(int p); int next(int n); int main(void) { int x; int a,b=2; do { printf("Votre nombre (>1) :\n"); scanf("%d",&x); if (x<=1) printf("Que des valeurs >1 !\n"); } while(x<=1); a=x; printf("Methode avec Next !\n"); while (a>b) { if ((a%b)==0){ printf("%d\n",b); a/=b; } else b=next(b); } printf("%d\n",a); return(0); /* ©2002 All Rights Reserved to Didier STRAUS www.Software-DS.com */ } int premier(int p) { int i=2; while ((i<p) && ((p%i)!=0)) { i++; } if (i==p) return(1); else return(0); } int next(int n){ do { n++; } while(premier(n)==0); return(n); } |
Haut de la page - Page générée en 0.01415 sec.
|