update
This commit is contained in:
62
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q1_Singletons.c
Normal file
62
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q1_Singletons.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
// vérifie si le reel est déjà présent dans la liste
|
||||
int verificateur(double* adresseDebut, double* adresseEmplacement){
|
||||
while (adresseDebut<adresseEmplacement){
|
||||
if (*adresseDebut==*adresseEmplacement){
|
||||
return 0;
|
||||
adresseDebut++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main (void){
|
||||
int nbReel;
|
||||
int numReel=1;
|
||||
double* adresseDebut;
|
||||
double* adresseEmplacement;
|
||||
double valeurSaisis;
|
||||
printf("Choisissez le nombre de reel que vous voulez saisir : ");
|
||||
scanf("%d",&nbReel);
|
||||
adresseDebut = (double*) calloc(nbReel, sizeof (double));
|
||||
adresseEmplacement = adresseDebut;
|
||||
//lorsqu'il y a qu'un entier
|
||||
if (nbReel==1){
|
||||
printf("Saisissez votre reel : ");
|
||||
scanf("%lf",adresseEmplacement);
|
||||
printf("%lf %d\n",*adresseEmplacement, adresseEmplacement);
|
||||
}
|
||||
else{
|
||||
// premier reels
|
||||
if (nbReel>1){
|
||||
printf("Saisissez votre 1er reel : ");
|
||||
scanf("%lf",adresseEmplacement);
|
||||
printf("%lf %d\n",*adresseEmplacement, adresseEmplacement);
|
||||
// autres reels
|
||||
for (numReel=2;numReel<nbReel;numReel++){
|
||||
//adresseEmplacement++;
|
||||
printf("Saisissez votre %deme reel : ",numReel);
|
||||
scanf("%lf",&valeurSaisis);
|
||||
if (verificateur(adresseDebut, adresseEmplacement)==1){
|
||||
adresseEmplacement++;
|
||||
*adresseEmplacement=valeurSaisis;
|
||||
printf("%lf %d\n",*adresseEmplacement, adresseEmplacement);
|
||||
}
|
||||
}
|
||||
// dernier reel
|
||||
printf("Saisissez votre dernier reel : ");
|
||||
scanf("%lf",&valeurSaisis);
|
||||
if (verificateur(adresseDebut,adresseEmplacement)==1){
|
||||
adresseEmplacement++;
|
||||
*adresseEmplacement=valeurSaisis;
|
||||
printf("%lf %d\n",*adresseEmplacement, adresseEmplacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (;adresseEmplacement>=adresseDebut; adresseEmplacement--){
|
||||
printf("%lf \n",*adresseEmplacement);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
35
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q2_Palindrome.c
Normal file
35
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q2_Palindrome.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
char* inverse(const char* s){
|
||||
int emplacementS;
|
||||
int emplacementNewS;
|
||||
char* newS;
|
||||
emplacementS=strlen(s);
|
||||
newS = malloc((emplacementS+1)*sizeof (char));
|
||||
emplacementS--;
|
||||
for (emplacementNewS=0; emplacementS>=0; emplacementS--, emplacementNewS++){
|
||||
newS[emplacementNewS]=s[emplacementS];
|
||||
}
|
||||
newS[emplacementNewS+1]='\0';
|
||||
return newS;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int numArg;
|
||||
char* p;
|
||||
for (numArg=1;numArg<argc; numArg++){
|
||||
p = (char*) inverse(argv[numArg]);
|
||||
printf("%s ", argv[numArg]);
|
||||
if (p==argv[numArg]){
|
||||
printf("est un palindrome\n");
|
||||
}
|
||||
else{
|
||||
printf("n'est pas un palindrome\n");
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
46
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q4_Premiers.c
Normal file
46
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q4_Premiers.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int premier(int nb){
|
||||
int diviseur;
|
||||
if (nb<2){
|
||||
return 0;
|
||||
}
|
||||
if (nb==2){
|
||||
return 1;
|
||||
}
|
||||
if (nb>2){
|
||||
for (diviseur=2; diviseur<nb;diviseur++){
|
||||
if (nb%diviseur==0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int nbSaisis;
|
||||
int* p= (int*) malloc(sizeof(int));
|
||||
int taille=0;
|
||||
int numPremier;
|
||||
p[0]=2;
|
||||
printf("Bonjour, dans ce programme, vous allez saisir des entier n positifs.\nVous aurez en réponse, le nième nombre premier.\nSaisissez 0 pour quitter.\n");
|
||||
printf("Saisissez votre premier entier positif : ");
|
||||
scanf("%d\n", &nbSaisis);
|
||||
while (nbSaisis!=0) {
|
||||
if (nbSaisis>taille){
|
||||
p = (int*) realloc(p, nbSaisis*sizeof (int));
|
||||
for (numPremier=taille;numPremier<nbSaisis;numPremier++){
|
||||
int valPremier;
|
||||
for (valPremier=p[numPremier-1]+1;premier(valPremier)!=1;valPremier++){}
|
||||
p[numPremier]=valPremier;
|
||||
}
|
||||
taille=nbSaisis;
|
||||
}
|
||||
printf("%d\n",p[nbSaisis-1]);
|
||||
printf("Saisissez un autre entier : ");
|
||||
scanf("%d", &nbSaisis);
|
||||
}
|
||||
printf("Au revoir...");
|
||||
}
|
46
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q4_Premiers.c~
Normal file
46
DEV/DEV1.1_suite/TP01_AllocationDynamique/Q4_Premiers.c~
Normal file
@@ -0,0 +1,46 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int premier(int nb){
|
||||
int diviseur;
|
||||
if (nb<2){
|
||||
return 0;
|
||||
}
|
||||
if (nb==2){
|
||||
return 1;
|
||||
}
|
||||
if (nb>2){
|
||||
for (diviseur=2; diviseur<nb;diviseur++){
|
||||
if (nb%diviseur==0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int nbSaisis;
|
||||
int* p= (int*) malloc(sizeof(int));
|
||||
int taille=0;
|
||||
int numPremier;
|
||||
p[0]=2;
|
||||
printf("Bonjour, dans ce programme, vous allez saisir des entier n positifs.\nVous aurez en réponse, le nième nombre premier.\nSaisissez 0 pour quitter.\n");
|
||||
printf("Saisissez votre premier entier positif : ");
|
||||
scanf("%d\n", &nbSaisis);
|
||||
while (nbSaisis!=0) {
|
||||
if (nbSaisis>taille){
|
||||
p = (int*) realloc(p, nbSaisis*sizeof (int));
|
||||
for (numPremier=taille;numPremier<nbSaisis;numPremier++){
|
||||
int valPremier;
|
||||
for (valPremier=p[numPremier-1]+1;premier(valPremier)!=1;valPremier++){}
|
||||
p[numPremier]=valPremier;
|
||||
}
|
||||
taille=nbSaisis;
|
||||
}
|
||||
printf("%d\n",p[nbSaisis-1]);
|
||||
printf("Saisissez un autre entier : ");
|
||||
scanf("%d", &nbSaisis);
|
||||
}
|
||||
printf("Au revoir...");
|
||||
}
|
BIN
DEV/DEV1.1_suite/TP01_AllocationDynamique/exe
Executable file
BIN
DEV/DEV1.1_suite/TP01_AllocationDynamique/exe
Executable file
Binary file not shown.
Reference in New Issue
Block a user