Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coursDeProg
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
yassin.elhakoun
coursDeProg
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
Changes
2
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
PDF
=
$(
MD:%.md
=
%.pdf
)
# Pour les fichier pdf on transforme .md -> .pdf
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) # 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
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() {
# Structures de contrôle: `if`{.C} .. `else if`{.C} .. `else`{.C} (1/2)
\f
ootnotesize
## Syntaxe
```
C
...
...
@@ -81,6 +83,8 @@ if (x) { // si x s'évalue à `vrai`
# Structures de contrôle: `continue`{.C}, `break`{.C}
\f
ootnotesize
-
`continue`
{.C} saute à la prochaine itération d'une boucle.
```C
...
...
@@ -136,7 +140,7 @@ int main() {
$
./prog
$
echo
$?
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é
```
...
...
@@ -160,12 +164,16 @@ ERROR # si tout s'est mal passé
```
C
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Hello world.\n");
int val = 1;
printf("Hello world %d time.\n", val);
printf("%f squared is equal to %f.\n", 2.5, 2.5*2.5);
// %d => int
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;
}
```
...
...
@@ -194,7 +202,7 @@ int main() {
int main() {
printf("Enter 3 numbers: \n");
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);
return EXIT_SUCCESS;
...
...
@@ -203,6 +211,8 @@ int main() {
# Nombres aléatoires: `rand()`, `srand()`{.C} (2/2)
\f
ootnotesize
```
$ man 3 rand
The rand() function returns a pseudo-random integer
...
...
@@ -220,10 +230,43 @@ int main() {
srand(0); // every run will be identical
srand(time(NULL)); // every run will be be different
for (int i = 0; i < 50; ++i) {
printf("%d\n", rand() % 50);
printf("%d\n", rand() % 50);
// à quoi sert % 50?
}
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