Controle Machine 2
This commit is contained in:
parent
64944874bc
commit
c7ec385a55
18
APL1.1/CM2/conversion.c
Normal file
18
APL1.1/CM2/conversion.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FACTOR 2.54
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
double length = strtod(argv[1], NULL), new_length;
|
||||
if (!strcmp(argv[2], "cm")) { /*On veut convertir en pouces*/
|
||||
new_length = length / FACTOR;
|
||||
printf("%1.3fcm = %1.3fin\n", length, new_length);
|
||||
} else { /*On veut convertir en centimètres*/
|
||||
new_length = length * FACTOR;
|
||||
printf("%1.3fin = %1.3fcm\n", length, new_length);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
23
APL1.1/CM2/inverse.c
Normal file
23
APL1.1/CM2/inverse.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NBINT 5
|
||||
|
||||
void reverse(int state) {
|
||||
int entier;
|
||||
printf("Entier n° %d : ", NBINT - state + 1);
|
||||
scanf("%d", &entier);
|
||||
|
||||
if (state != 1) /*On demande les autres entiers avant de print !*/
|
||||
reverse(state-1);
|
||||
|
||||
printf("%d ", entier);
|
||||
|
||||
if (state == NBINT)
|
||||
putchar('\n'); /*On retourne à la ligne à la fin.*/
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
reverse(NBINT);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
17
APL1.1/CM2/lancer.c
Normal file
17
APL1.1/CM2/lancer.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
FILE* file = fopen("/dev/random", "r");
|
||||
if (file) {
|
||||
unsigned char randVal;
|
||||
fread(&randVal, 1, 1, file);
|
||||
|
||||
printf("%d\n", (randVal % 6) + 1);
|
||||
} else {
|
||||
puts("Impossible d'ouvrir le fichier.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
32
APL1.1/CM2/semaine.c
Normal file
32
APL1.1/CM2/semaine.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
char weekDays[7][9] = {
|
||||
"dimanche",
|
||||
"lundi",
|
||||
"mardi",
|
||||
"mercredi",
|
||||
"jeudi",
|
||||
"vendredi",
|
||||
"samedi"
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
int day, month, year;
|
||||
printf("Donnez une date au format jj/mm/aa : ");
|
||||
scanf("%d/%d/%d", &day, &month, &year);
|
||||
|
||||
year += 100; /*On assume que les dates données sont des années 2XXX*/
|
||||
month -= 1;
|
||||
|
||||
struct tm partialDate = {};
|
||||
partialDate.tm_mday = day;
|
||||
partialDate.tm_mon = month;
|
||||
partialDate.tm_year = year;
|
||||
|
||||
mktime(&partialDate);
|
||||
printf("C'est un %s.\n", weekDays[partialDate.tm_wday]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user