Ajout des TP
This commit is contained in:
18
BUT1/CONTROLE/CM1/.vscode/c_cpp_properties.json
vendored
Normal file
18
BUT1/CONTROLE/CM1/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
24
BUT1/CONTROLE/CM1/.vscode/launch.json
vendored
Normal file
24
BUT1/CONTROLE/CM1/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/export/home/an23/stiti/Desktop/DEV/CM1",
|
||||
"program": "/export/home/an23/stiti/Desktop/DEV/CM1/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
37
BUT1/CONTROLE/CM1/.vscode/settings.json
vendored
Normal file
37
BUT1/CONTROLE/CM1/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wconversion",
|
||||
"-Wnull-dereference",
|
||||
"-Wsign-conversion"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false
|
||||
}
|
10
BUT1/CONTROLE/CM1/exo1.c
Normal file
10
BUT1/CONTROLE/CM1/exo1.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
printf(" {o,o}\n");
|
||||
printf(" (__(\\\n");/* On rajoute un "\" pour préciser que le \ d'avant ne sert pas à dire que le caractère d'après est spécial"*/
|
||||
printf(" -\"-\"- "); /*idem ici avec les guillemets*/
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
9
BUT1/CONTROLE/CM1/exo2.c
Normal file
9
BUT1/CONTROLE/CM1/exo2.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
printf("%d\n", 58);
|
||||
printf("%o\n", 47); /* IMPOSSIBLE A AFFICHER CAR LE 8 n'existe pas en base octal ... comme le 2 n'existe pas en base décimal donc 47 pour 57 à la limite*/
|
||||
printf("%x\n", 0x58);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
44
BUT1/CONTROLE/CM1/exo3.c
Normal file
44
BUT1/CONTROLE/CM1/exo3.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
double taille_utilisateur; /* taille en cm /// Justification nom de vaiable = taille_utilisateur car c'est la taille taper par l'utilisateur*/
|
||||
int i,pied=0,pouce=0;
|
||||
printf("Entrez votre taille : ");
|
||||
scanf("%lf",&taille_utilisateur); /* lf car c'est un double*/
|
||||
|
||||
/* S'occupe de retirer l'équivalent de 1 pied à la taille en cm et d'ajouter 1 à pied*/
|
||||
for(i=0;taille_utilisateur>=0.3048;i++){
|
||||
taille_utilisateur = taille_utilisateur - 0.3048;
|
||||
pied++;
|
||||
}
|
||||
|
||||
/* S'occupe de retirer l'équivalent de 1 pouce à la taille en cm et d'ajouter 1 à pouce*/
|
||||
for(i=0;taille_utilisateur>=0.0256;i++){
|
||||
taille_utilisateur = taille_utilisateur - 0.0256;
|
||||
pouce++;
|
||||
}
|
||||
|
||||
|
||||
if(pied>0){
|
||||
if(pied==1){
|
||||
printf("%d pied et",pied);
|
||||
}else{
|
||||
printf("%d pieds",pied);
|
||||
}
|
||||
}
|
||||
|
||||
if(pied>0 && pouce>0){
|
||||
printf(" et ");
|
||||
}
|
||||
|
||||
if(pouce>0){
|
||||
if(pouce==1){
|
||||
printf("%d pouce ",pouce);
|
||||
}else{
|
||||
printf("%d pouces ",pouce);
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
18
BUT1/CONTROLE/CM1/exo4.c
Normal file
18
BUT1/CONTROLE/CM1/exo4.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
char lettre,alphabet;
|
||||
printf("Entrez une minuscule : ");
|
||||
scanf("%c", &lettre); /* ou lettre = getchar() mais cela reviens au même*/
|
||||
alphabet = 'a';
|
||||
/* Je n'ai trouver aucune solution pour utiliser une boucle for dans cette situation (Désoler...)*/
|
||||
while(alphabet <= 'z'){
|
||||
(alphabet != lettre) && printf("%c", alphabet);
|
||||
(alphabet == lettre) && printf("[%c]", alphabet);
|
||||
alphabet++;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
36
BUT1/CONTROLE/CM1/exo5.c
Normal file
36
BUT1/CONTROLE/CM1/exo5.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int des[5];
|
||||
int j,i;
|
||||
int maxOccurrences = 0, occurrences;
|
||||
|
||||
for (i=0;i<5;i++) {
|
||||
printf("Jet n°%d : ", i + 1);
|
||||
scanf("%d",&des[i]);
|
||||
|
||||
/*Vérifier que la valeur donner est entre 1 et 6*/
|
||||
if(des[i]<1 || des[i]>6) {
|
||||
printf("Veuillez entrer un entier entre 1 et 6.\n");
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
/*Compter les occurrences de chaque nombre*/
|
||||
for(i=1;i<=6;i++){
|
||||
occurrences = 0;
|
||||
for(j=0;j<5;j++){
|
||||
if(des[j] == i){
|
||||
occurrences++;
|
||||
}
|
||||
}
|
||||
if(occurrences > maxOccurrences){
|
||||
maxOccurrences = occurrences;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Occurrences maximum : %d\n", maxOccurrences);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
51
BUT1/CONTROLE/CM3/exo1/exo1.c
Normal file
51
BUT1/CONTROLE/CM3/exo1/exo1.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void modifierImage(char *nomFichier) {
|
||||
int pixel, largeur, hauteur, intensiteMax;
|
||||
char commentaire[256],enTete[3];
|
||||
FILE *fichier = fopen(nomFichier, "r+");
|
||||
|
||||
if (fichier == NULL) {
|
||||
fprintf(stderr,"Impossible d'ouvrir le fichier !");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Lire l'en-tête */
|
||||
fscanf(fichier, "%2s", enTete);
|
||||
|
||||
if (enTete[0] != 'P' || enTete[1] != '2') {
|
||||
printf("Le fichier n'est pas au format PPM ASCII.\n");
|
||||
fclose(fichier);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ignorer les commentaires s'il y en a*/
|
||||
while (fgetc(fichier) == '#') {
|
||||
fgets(commentaire, sizeof(commentaire), fichier);
|
||||
}
|
||||
|
||||
/* Lire les dimensions et l'intensité maximale*/
|
||||
fscanf(fichier, "%d %d %d", &largeur, &hauteur, &intensiteMax);
|
||||
|
||||
/* Modifier les pixels du message en blanc*/
|
||||
fseek(fichier, ftell(fichier), SEEK_SET); /* Revenir au début des données d'image*/
|
||||
|
||||
while ((pixel = fgetc(fichier)) != EOF) {
|
||||
/* Modifier uniquement les pixels correspondant au message (intensité 3)*/
|
||||
if (pixel == 3) {
|
||||
fseek(fichier, -1, SEEK_CUR);
|
||||
fprintf(fichier, "5 ");
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fichier);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char nomFichier[] = "image.pgm";
|
||||
modifierImage(nomFichier);
|
||||
printf("Modification terminée avec succès.\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
0
BUT1/CONTROLE/CM3/exo1/image.pgm
Normal file
0
BUT1/CONTROLE/CM3/exo1/image.pgm
Normal file
47
BUT1/CONTROLE/CM3/exo2/exo2.c
Normal file
47
BUT1/CONTROLE/CM3/exo2/exo2.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Fonction récursive pour trouver le maximum entre deux entiers*/
|
||||
int maxRecursif(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
/* Fonction récursive pour trouver le maximum dans un tableau d'entiers*/
|
||||
int maxTableauRecursif(int tableau[], int taille) {
|
||||
if (taille == 1) {
|
||||
return tableau[0];
|
||||
}
|
||||
|
||||
return maxRecursif(tableau[taille - 1], maxTableauRecursif(tableau, taille - 1));
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int i,max;
|
||||
int* entiers;
|
||||
if (argc < 2) {
|
||||
perror("Usage: ./a.out <entier1> <entier2> <entierN>\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Allouer de la mémoire pour stocker les entiers fournis en ligne de commande*/
|
||||
entiers = (int*)malloc((argc - 1) * sizeof(int));
|
||||
|
||||
if (entiers == NULL) {
|
||||
perror("Erreur d'allocation mémoire");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Convertir les arguments en entiers et les stocker dans le tableau*/
|
||||
for (i = 1; i < argc; i++) {
|
||||
entiers[i - 1] = atoi(argv[i]);
|
||||
}
|
||||
|
||||
/* Trouver et afficher le plus grand entier récursivement*/
|
||||
max = maxTableauRecursif(entiers, argc - 1);
|
||||
printf("%d\n", max);
|
||||
|
||||
/* Libérer la mémoire allouée pour le tableau*/
|
||||
free(entiers);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
98
BUT1/CONTROLE/CM3/exo3/exo3.c
Normal file
98
BUT1/CONTROLE/CM3/exo3/exo3.c
Normal file
@@ -0,0 +1,98 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Structure pour un nœud dans la liste chaînée*/
|
||||
typedef struct Noeud {
|
||||
int digit;
|
||||
struct Noeud* suivant;
|
||||
} Noeud;
|
||||
|
||||
/* Fonction pour convertir une représentation décimale en liste chaînée*/
|
||||
Noeud* convertirListeChainee(char* nombre) {
|
||||
Noeud* liste = NULL;
|
||||
int i;
|
||||
int length = strlen(nombre);
|
||||
|
||||
for (i = length - 1; i >= 0; i--) {
|
||||
Noeud* nouveauNoeud = (Noeud*)malloc(sizeof(Noeud));
|
||||
nouveauNoeud->digit = nombre[i] - '0';
|
||||
nouveauNoeud->suivant = liste;
|
||||
liste = nouveauNoeud;
|
||||
}
|
||||
|
||||
return liste;
|
||||
}
|
||||
|
||||
/* Fonction pour afficher une liste chaînée*/
|
||||
void AfficherListe(Noeud* liste) {
|
||||
while (liste != NULL) {
|
||||
printf("%d", liste->digit);
|
||||
liste = liste->suivant;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Fonction pour additionner deux listes chaînées*/
|
||||
Noeud* ajouterAListe(Noeud* num1, Noeud* num2) {
|
||||
Noeud* resultat = NULL;
|
||||
Noeud* actuel = NULL;
|
||||
Noeud* nouveauNoeud = NULL;
|
||||
int retenue = 0;
|
||||
int somme;
|
||||
|
||||
while (num1 != NULL || num2 != NULL || retenue != 0) {
|
||||
somme = retenue;
|
||||
|
||||
if (num1 != NULL) {
|
||||
somme += num1->digit;
|
||||
num1 = num1->suivant;
|
||||
}
|
||||
|
||||
if (num2 != NULL) {
|
||||
somme += num2->digit;
|
||||
num2 = num2->suivant;
|
||||
}
|
||||
|
||||
nouveauNoeud = (Noeud*)malloc(sizeof(Noeud));
|
||||
nouveauNoeud->digit = somme % 10;
|
||||
nouveauNoeud->suivant = NULL;
|
||||
|
||||
retenue = somme / 10;
|
||||
|
||||
if (resultat == NULL) {
|
||||
resultat = nouveauNoeud;
|
||||
actuel = resultat;
|
||||
} else {
|
||||
actuel->suivant = nouveauNoeud;
|
||||
actuel = nouveauNoeud;
|
||||
}
|
||||
}
|
||||
|
||||
return resultat;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
Noeud* num1 = NULL;
|
||||
Noeud* num2 = NULL;
|
||||
Noeud* somme = NULL;
|
||||
char* nombre1;
|
||||
char* nombre2;
|
||||
if (argc != 3) {
|
||||
perror("Usage: %s <nombre1> <nombre2>\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
nombre1 = argv[1];
|
||||
nombre2 = argv[2];
|
||||
|
||||
|
||||
num1 = convertirListeChainee(nombre1);
|
||||
num2 = convertirListeChainee(nombre2);
|
||||
somme = ajouterAListe(num1, num2);
|
||||
|
||||
|
||||
AfficherListe(somme);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
BUT1/CONTROLE/stiti_CM1.tar.gz
Normal file
BIN
BUT1/CONTROLE/stiti_CM1.tar.gz
Normal file
Binary file not shown.
BIN
BUT1/CONTROLE/stiti_CM3.tar.gz
Normal file
BIN
BUT1/CONTROLE/stiti_CM3.tar.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user