CM2
This commit is contained in:
parent
a10b396365
commit
eecd0b6aa6
@ -0,0 +1,19 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
int main(int argc, char * argv[]){
|
||||
char* temp;
|
||||
char* type;
|
||||
double valeur;
|
||||
type = argv[2];
|
||||
valeur = strtod(argv[1],&temp);
|
||||
double conversion = 2.54;
|
||||
if (strcmp(type,"cm")==0){
|
||||
printf("%.2lf in\n",valeur / conversion);
|
||||
}
|
||||
if (strcmp(type,"in")==0){
|
||||
printf("%.2lf cm\n",valeur * conversion);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
67
APL1.1/CM2/inverse.c
Normal file
67
APL1.1/CM2/inverse.c
Normal file
@ -0,0 +1,67 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct maillon_s {
|
||||
struct maillon_s* suivant;
|
||||
int value;
|
||||
struct maillon_s* premier;
|
||||
|
||||
} maillon;
|
||||
|
||||
int Empty(maillon* premier) {
|
||||
if (premier == NULL) {
|
||||
return 1;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void Push(int value, maillon* premier) {
|
||||
maillon* p = malloc(sizeof(maillon));
|
||||
if (!Empty(premier)) {
|
||||
p->value = premier->value;
|
||||
p->suivant = premier->suivant;
|
||||
premier->suivant = p;
|
||||
premier->value = value;
|
||||
} else {
|
||||
premier->value = value;
|
||||
}
|
||||
}
|
||||
|
||||
int Pop(maillon* premier) {
|
||||
maillon* p;
|
||||
int value;
|
||||
if (Empty(premier)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
value = premier->value;
|
||||
if (premier->suivant==NULL) {
|
||||
premier = NULL;
|
||||
} else {
|
||||
p = premier->suivant;
|
||||
premier->value = p->value;
|
||||
premier->suivant = p->suivant;
|
||||
free(p);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void AfficherListe(maillon* premier) {
|
||||
maillon* p;
|
||||
for (p=premier ; p != NULL; p = p->premier) {
|
||||
printf("%u %u %u %u %u", p->value);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char const argv[]) {
|
||||
int entier;
|
||||
int i;
|
||||
maillon* premier = malloc(sizeof(maillon));
|
||||
for(i=1;i<=5;i++) {
|
||||
printf("Entier n°%d : ",i);
|
||||
scanf("%d", &entier);
|
||||
Push(entier, premier);
|
||||
}
|
||||
AfficherListe(premier);
|
||||
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>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char const argv[])
|
||||
{
|
||||
FILE *flux;
|
||||
int temp=0;
|
||||
flux = fopen("/dev/random", "r");
|
||||
if(flux)
|
||||
{
|
||||
fread(&temp,sizeof(int),1,flux);
|
||||
printf("%d\n", temp%6);
|
||||
fclose(flux);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
37
APL1.1/CM2/semaine.c
Normal file
37
APL1.1/CM2/semaine.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
int main(int argc, char *argv[]){
|
||||
struct tm time;
|
||||
int jour = time.tm_mday;
|
||||
int mois = time.tm_mon;
|
||||
int annee = time.tm_year;
|
||||
int jour_lettre = 0;
|
||||
printf ("Entrez une date : \n");
|
||||
scanf("%d/%d/%d",&jour,&mois,&annee);
|
||||
time.tm_year = annee;
|
||||
time.tm_mon = mois;
|
||||
time.tm_mday = jour;
|
||||
if (time.tm_mday%6+1 == 0){
|
||||
printf("C'est un Dimanche\n");
|
||||
}
|
||||
if (time.tm_mday%6+1 == 1){
|
||||
printf("C'est un Lundi\n");
|
||||
}
|
||||
if (time.tm_mday%6+1 == 2){
|
||||
printf("C'est un Mardi\n");
|
||||
}
|
||||
if (time.tm_mday%6+1 == 3){
|
||||
printf("C'est un Mercredi\n");
|
||||
}
|
||||
if (time.tm_mday%6+1 == 4){
|
||||
printf("C'est un Jeudi\n");
|
||||
}
|
||||
if (time.tm_mday%6+1 == 5){
|
||||
printf("C'est un Vendredi\n");
|
||||
}
|
||||
if (time.tm_mday%6+1 == 6){
|
||||
printf("C'est un Samedi\n");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
19
utilitaire/debordement.c
Normal file
19
utilitaire/debordement.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
unsigned long int l;
|
||||
int n = 1;
|
||||
|
||||
|
||||
l = 1;
|
||||
while (l*n != 0) {
|
||||
l *= n;
|
||||
n++;
|
||||
}
|
||||
n -= 1;
|
||||
|
||||
|
||||
printf("valeur de n = %d, valeur de %d! = %lu\n", n, n, l);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user