TP06 Conditions

This commit is contained in:
HORVILLE 2021-09-24 10:19:20 +02:00
parent f217328b23
commit 33bfc43144
6 changed files with 200 additions and 0 deletions

39
APL1.1/TP06/couverture.c Normal file
View File

@ -0,0 +1,39 @@
#include<stdio.h>
#include<stdlib.h>
int min(int a, int b) {
return a < b ? a : b;
}
int max(int a, int b) {
return a > b ? a : b;
}
int main(int argc, char * argv[]) {
int frais, result;
printf("Veuillez indiquer le montant total des réparations : ");
result = scanf("%d", &frais);
if (result != 1) {
printf("Format invalide.\n");
return EXIT_FAILURE;
}
int part_assure, part_assurance;
if ( frais <= 200 ) {
part_assure = frais;
part_assurance = 0;
} else if (frais <= 2000) {
part_assure = 200;
part_assurance = frais - 200;
} else {
part_assure = min(frais/10, 800);
part_assurance = frais - part_assure;
}
printf("L'assuré prendra en charge %d€ et l'assurance %d€.\n", part_assure, part_assurance);
return EXIT_SUCCESS;
}

41
APL1.1/TP06/maximum.c Normal file
View File

@ -0,0 +1,41 @@
#include<stdio.h>
#include<stdlib.h>
int proposeInt() {
printf("Veuillez donner un entier : ");
}
int checkResult(int result) {
if (result == 0) {
printf("Format Incorrect.\n");
return 0;
}
return 1;
}
int main(int argc, char * argv[]) {
int max, min;
printf("%d", &max);
proposeInt();
int result1 = scanf("%d", &max);
if (!checkResult(result1)) return EXIT_FAILURE;
proposeInt();
int result2 = scanf("%d", &min);
if (!checkResult(result2)) return EXIT_FAILURE;
max = max>min ? max : min;
proposeInt();
int result3 = scanf("%d", &min);
if (!checkResult(result3)) return EXIT_FAILURE;
max = max>min ? max : min;
printf("Le maximum de ces trois valeurs est %d.\n", max);
return EXIT_SUCCESS;
}

28
APL1.1/TP06/mention.c Normal file
View File

@ -0,0 +1,28 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
int note, result;
printf("Veuillez donner votre note du Bac : ");
result = scanf("%d", &note);
if (result == 1) {
if (note >= 16) {
printf("Vous avez eu le bac avec mention 'Très Bien', féliciations.\n");
} else if (note >= 14) {
printf("Vous avez eu le bac avec mention 'Bien', bon travail.\n");
} else if (note >= 12) {
printf("Vous avez eu le bac avec mention 'Assez Bien', satisfaisant.\n");
} else {
printf("Vous avez eu le bac sans mention.. Triste.\n");
}
return EXIT_SUCCESS;
} else {
printf("Format invalide.\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

37
APL1.1/TP06/ordre.c Normal file
View File

@ -0,0 +1,37 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
int int1, int2, int3, result;
printf("Veuillez donner trois entiers : ");
result = scanf("%d %d %d", &int1, &int2, &int3);
if (result != 3) {
printf("Format invalide.\n");
return EXIT_FAILURE;
}
if (int1 > int2) {
int temp_int = int1;
int1 = int2;
int2 = temp_int;
}
if (int1 > int3) {
int temp_int = int1;
int1 = int3;
int3 = temp_int;
}
if (int2 > int3) {
int temp_int = int2;
int2 = int3;
int3 = temp_int;
}
printf("Dans l'ordre croissant : %d, %d, %d.\n", int1, int2, int3);
return EXIT_SUCCESS;
}

23
APL1.1/TP06/produit.c Normal file
View File

@ -0,0 +1,23 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
int arg1, arg2, result;
printf("Veuillez entrer deux entiers :");
result = scanf("%d %d", &arg1, &arg2);
if (result == 2) {
if ((arg1 < 0 || arg2 < 0) && !(arg1 < 0 && arg2 < 0)) {
//On print le résultat pour vérifier.
printf("Le résultat sera négatif (%d).\n", arg1 * arg2);
return EXIT_SUCCESS;
} else {
printf("Le résultat sera positif (%d).\n", arg1 * arg2);
}
} else {
printf("Format incorrect.\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

32
APL1.1/TP06/triple.c Normal file
View File

@ -0,0 +1,32 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
printf("Veuillez donner un entier naturel : ");
int entier, result;
result = scanf("%d", &entier);
if (entier < 0) {
printf("L'entier doit être supérieur ou égal à 0.\n");
return EXIT_FAILURE;
}
if (result == 1) {
int remainder = entier % 3;
int triple;
if (remainder == 0) {
triple = entier;
} else if (remainder == 1) {
triple = entier - 1;
} else {
triple = entier + 1;
}
printf("Le multiple de trois le plus proche est %d.\n", triple);
} else {
printf("Format invalide.\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}