Skip to content
Snippets Groups Projects
Verified Commit 3994a40b authored by orestis.malaspin's avatar orestis.malaspin
Browse files

maj boucles et conditions

parent 282156c8
Branches
No related tags found
No related merge requests found
Pipeline #19554 passed
...@@ -21,8 +21,8 @@ HTML=$(MD:%.md=%.html) # Pour les fichier html on transforme .md -> .html ...@@ -21,8 +21,8 @@ HTML=$(MD:%.md=%.html) # Pour les fichier html on transforme .md -> .html
PDF=$(MD:%.md=%.pdf) # Pour les fichier pdf on transforme .md -> .pdf PDF=$(MD:%.md=%.pdf) # Pour les fichier pdf on transforme .md -> .pdf
MARKDOWN=$(MD:%.md=%.markdown) # Pour les fichier markdown on transforme .md -> .markdown MARKDOWN=$(MD:%.md=%.markdown) # Pour les fichier markdown on transforme .md -> .markdown
all: $(PDF) $(HTML) # La cible par défaut (all) exécute les cibles %.html et %.pdf # all: $(PDF) $(HTML) # La cible par défaut (all) exécute les cibles %.html et %.pdf
# all: $(PDF) # La cible par défaut (all) exécute les cibles %.html et %.pdf all: $(PDF) # La cible par défaut (all) exécute les cibles %.html et %.pdf
markdown: $(MARKDOWN) # La markdown les cibles %.markdown markdown: $(MARKDOWN) # La markdown les cibles %.markdown
......
...@@ -55,6 +55,8 @@ int main() { ...@@ -55,6 +55,8 @@ int main() {
# Structures de contrôle: `if`{.C} .. `else if`{.C} .. `else`{.C} (1/2) # Structures de contrôle: `if`{.C} .. `else if`{.C} .. `else`{.C} (1/2)
\footnotesize
## Syntaxe ## Syntaxe
```C ```C
...@@ -81,6 +83,8 @@ if (x) { // si x s'évalue à `vrai` ...@@ -81,6 +83,8 @@ if (x) { // si x s'évalue à `vrai`
# Structures de contrôle: `continue`{.C}, `break`{.C} # Structures de contrôle: `continue`{.C}, `break`{.C}
\footnotesize
- `continue`{.C} saute à la prochaine itération d'une boucle. - `continue`{.C} saute à la prochaine itération d'une boucle.
```C ```C
...@@ -136,7 +140,7 @@ int main() { ...@@ -136,7 +140,7 @@ int main() {
$ ./prog $ ./prog
$ echo $? $ echo $?
0 # tout s'est bien passé par exemple 0 # tout s'est bien passé par exemple
$ if [ $? -eq 0 ]; then echo "OK" ; else echo "ERROR"; fi $ if [ $? -eq 0 ]; then echo "OK"; else echo "ERROR"; fi
ERROR # si tout s'est mal passé ERROR # si tout s'est mal passé
``` ```
...@@ -160,12 +164,16 @@ ERROR # si tout s'est mal passé ...@@ -160,12 +164,16 @@ ERROR # si tout s'est mal passé
```C ```C
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main() { int main() {
printf("Hello world.\n"); printf("Hello world.\n");
int val = 1; int val = 1;
printf("Hello world %d time.\n", val); // %d => int
printf("%f squared is equal to %f.\n", 2.5, 2.5*2.5); printf("Hello world %d time.\n", val);
// %f => float
printf("%f squared is equal to %f.\n",
2.5, 2.5*2.5);
// %s => string
printf("Hello world %s.\n", "Hello world");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
``` ```
...@@ -194,7 +202,7 @@ int main() { ...@@ -194,7 +202,7 @@ int main() {
int main() { int main() {
printf("Enter 3 numbers: \n"); printf("Enter 3 numbers: \n");
int i, j, k; int i, j, k;
scanf("%d %d %d", &i, &j, &k); scanf("%d %d %d", &i, &j, &k); // !!! &
printf("You entered: %d %d %d\n", i, j, k); printf("You entered: %d %d %d\n", i, j, k);
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -203,6 +211,8 @@ int main() { ...@@ -203,6 +211,8 @@ int main() {
# Nombres aléatoires: `rand()`, `srand()`{.C} (2/2) # Nombres aléatoires: `rand()`, `srand()`{.C} (2/2)
\footnotesize
``` ```
$ man 3 rand $ man 3 rand
The rand() function returns a pseudo-random integer The rand() function returns a pseudo-random integer
...@@ -220,10 +230,43 @@ int main() { ...@@ -220,10 +230,43 @@ int main() {
srand(0); // every run will be identical srand(0); // every run will be identical
srand(time(NULL)); // every run will be be different srand(time(NULL)); // every run will be be different
for (int i = 0; i < 50; ++i) { for (int i = 0; i < 50; ++i) {
printf("%d\n", rand() % 50); printf("%d\n", rand() % 50); // à quoi sert % 50?
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
``` ```
# Le cas du nombre secret
## But du programme
* Faire chercher un nombre aléatoire,
* Le nombre est compris entre 0 et une borne max.
## Quelles sont les étapes?
1. Donner une borne maximale à l'ordinateur, MAX.
. . .
2. Faire tirer un nombre aléatoire à l'ordinateur entre 0 et MAX-1.
. . .
3. Le·la joueur·se joue un nombre.
. . .
4. L'ordinateur vérifie la réponse:
* Si correct le jeu est fini,
* Sinon indiquer si le nombre secret est plus grand ou plus petit et revenir à 3.
# La fin
1. Y a-t-il des questions?
. .
2. Si oui, répondre et revenir à 1, sinon quitter le cours.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment