moitié tp 3

This commit is contained in:
2024-01-29 17:28:51 +01:00
parent cffb424f64
commit eb581c8a31
45 changed files with 964 additions and 16 deletions

37
DEV1.1/CM3/calcul.c Normal file
View File

@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct mail {
long int valeur;
struct mail* suivant;
};
typedef struct mail maillon;
void ajouter_fin(maillon* debut, double nouv){
maillon* p = (maillon*) malloc(sizeof(maillon*));
p->valeur = nouv;
maillon* fin;
fin = debut;
while(fin->suivant != NULL)
fin = fin->suivant;
fin->suivant = p;
p->suivant = NULL;
int affichage(maillon* debut){
if (debut->suivant == NULL){
printf("%f",debut->valeur);
return EXIT_SUCCESS;
}else
affichage(debut->suivant);
printf("%f",debut->valeur);
return EXIT_SUCCESS;
int main(int argc, char** argv){
long int val1, val2;
int i;
maillon* debut1 = NULL;
maillon* debut2 = NULL;
val1 = strtol(argv[1],NULL,10);
val2 = strtol(argv[2],NULL,10);

27
DEV1.1/CM3/culmination1.c Normal file
View File

@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*la variable grand lors du début du programme est la première valeur du tableau
et le tableau ne contient pas son premier élément*/
long int superieur(long int tab[], int taille, long int grand){
if (taille < 1)
return grand;
else if (tab[0] > grand)
grand = tab[0];
printf("n\n");
superieur( tab+1, taille-1, grand);
}
int main(int argc, char** argv){
long int val;
int i;
long int* tab= (long int*) malloc(argc*sizeof(long int));
for (i = 1; i < argc; i++){
val = strtol(argv[i],NULL,10);
tab[i-1] = val;
}
val = superieur( tab+1, argc-1, tab[0]);
printf("%ld\n",val);
return EXIT_SUCCESS;
}

24
DEV1.1/TP27/culmination.c Normal file
View File

@@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*la variable grand lors du début du programme est la première valeur du tableau
et le tableau ne contient pas son premier élément*/
int superieur(long int tab[], int taille, long int grand){
if (taille < 1)
return grand;
else if (tab[0] > grand)
grand = tab[0];
return superieur( tab[]+1, taille-1, grand);
int main(int argc, char** argv){
long int val;
int i;
log int tab[argc];
for (i = 1; i < argc; i++){
val = strtol(argv[i]);
tab[i-1] = val;
}
val = superieur( tab[]+1, argc-1, tab[0]);
printf("%ld\n",val);
return EXIT_SUCCESS;

20
DEV1.1/TP28/Makefile Normal file
View File

@@ -0,0 +1,20 @@
but : pile
OFILES = main.o\
chaine.o\
CC = gcc
CFLAGS = -Wall -ansi -pedantic -g
main.o : chaine.h
chaine.o : chaine.h
pile : $(OFILES)
$(CC) $(CFLAGS) -o pile $(OFILES)
clean :
-rm -f $(OFILES) pile
.PHONY : but clean

View File

@@ -1,28 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include "chaine.h"
struct maillon_s {
char valeur;
struct maillon_s* suivant;
};
typedef struct maillon_s maillon ;
void push(char nouv, maillon* debut){
void push(char nouv, maillon** debut){
maillon* m = (maillon*) malloc (sizeof(maillon));
m->valeur = nouv;
if (debut == NULL)
m->suivant = NULL;
else
m->suivant = debut;
debut = m;
m->suivant = *debut;
*debut = m;
}
void pop(maillon* debut){
maillon* m = (maillon*) malloc (sizeof(maillon));
m->valeur = nouv;
if (debut == NULL)
m->suivant = NULL;
double pop(maillon** debut){
maillon m = **debut;
free(*debut);
if (m.suivant == NULL)
*debut = NULL;
else
m->suivant = debut;
debut = m;
*debut = m.suivant;
return m.valeur;
}
int empty(const maillon* debut){
return debut == NULL;
}
double top (const maillon* debut){
return debut->valeur;
}
void clear (maillon** debut){
while (empty(*debut)){
pop(debut);
}
}

14
DEV1.1/TP28/chaine.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef CHAINE_H
#define CHAINE_H
struct maillon_s {
char valeur;
struct maillon_s* suivant;
};
typedef struct maillon_s maillon ;
void push(char nouv, maillon** debut);
double pop(maillon** debut);
int empty(const maillon* debut);
#endif

14
DEV1.1/TP28/extra.c Normal file
View File

@@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include "extra.h"
#include "chaine.h"
double top (const maillon* debut){
return debut->valeur;
}
void clear (maillon** debut){
while (empty(*debut)){
pop(debut);
}
}

7
DEV1.1/TP28/extra.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef EXTRA_H
#define EXTRA_H
double top (const maillon* debut);
void clear (maillon** debut);
#endif

40
DEV1.1/TP28/main.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include "chaine.h"
#include "extra.h"
int main(void){
char op, valeur;
maillon* debut = NULL;
printf("La pile attend vos ordres\n");
printf("> ");
op = getchar();
while (op != 'q'){
if (op == '-'){
if (empty(debut)){
printf("La pile est vide !\n");
printf("> ");
}else{
valeur = pop(&debut);
printf("Le caractère %c a été supprimé\n", valeur);
printf("> ");
}
}else if (op == '+'){
valeur = getchar();
printf("Le caractère %c a été ajouté\n", valeur);
push(valeur, &debut);
printf("> ");
}else if (op == '/'){
clear(&debut);
printf("La pile est vide !\n");
printf("> ");
}else if (op == '='){
valeur = top(debut);
printf("Le caractère le plus récent est %c\n", valeur);
printf("> ");
}
op = getchar();
}
printf("au revoir\n");
return EXIT_SUCCESS;
}

BIN
DEV1.1/TP28/pile Executable file

Binary file not shown.

BIN
DEV1.1/felix-vi_CM3.tar.gz Normal file

Binary file not shown.