Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
programmation_sequentielle
cours
Commits
3994a40b
Verified
Commit
3994a40b
authored
2 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
maj boucles et conditions
parent
282156c8
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#19554
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
slides/Makefile
+2
-2
2 additions, 2 deletions
slides/Makefile
slides/boucles_conditions.md
+49
-6
49 additions, 6 deletions
slides/boucles_conditions.md
with
51 additions
and
8 deletions
slides/Makefile
+
2
−
2
View file @
3994a40b
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
slides/boucles_conditions.md
+
49
−
6
View file @
3994a40b
...
@@ -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)
\f
ootnotesize
## 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}
\f
ootnotesize
-
`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)
\f
ootnotesize
```
```
$ 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.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment