moitié tp 3
This commit is contained in:
59
prepa_CM3/ex1_A.c
Normal file
59
prepa_CM3/ex1_A.c
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct mail {
|
||||
int valeur;
|
||||
struct mail* suivant;
|
||||
};
|
||||
typedef struct mail maillon;
|
||||
|
||||
|
||||
int test(maillon* premier,int new){
|
||||
if(premier==NULL){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (new % premier->valeur==0)
|
||||
return 0;
|
||||
test(premier->suivant,new);
|
||||
}
|
||||
|
||||
|
||||
maillon* ajouter_debut(maillon* premier, int nouveau) {
|
||||
maillon* p = (maillon*) malloc(sizeof(maillon));
|
||||
if (p) {
|
||||
p->suivant = premier;
|
||||
p->valeur = nouveau;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
int currentNumber, stop=1;
|
||||
maillon* debut=NULL;
|
||||
|
||||
while (stop) {
|
||||
printf("Entrez un entier : ");
|
||||
scanf("%d", ¤tNumber);
|
||||
|
||||
if (currentNumber <= 0) {
|
||||
printf("Fin du programme.\n");
|
||||
stop=0;
|
||||
}
|
||||
|
||||
|
||||
if (test(debut,currentNumber)==0) {
|
||||
printf("Perdu !\n");
|
||||
stop=0;
|
||||
}
|
||||
debut=ajouter_debut(debut,currentNumber);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user