Vous êtes sur la page 1sur 24

!

"
#

2
$

!
!

% & # ' ( ' % 4 ' ( 0 & 3 ,


) *' - 5 " 0 ' 0
' '
- 5 " 0
% # ' ' &
- 6' " #
' + , + #
- "" "
% 7 ' ( 3 +
- . "" ' + /0 1 232
"
' #
' & #
% 7 0 ' 0
' " ' '
& & ' # ' ""
' ' '
&
4 5
$ $
" "

% $ &
<NOM_ALGORITHME> Nom de l'algorithme
' 8 VAR
' 9 ! + ,
9 9 & # 9 ' <déclaration1>
<déclaration2>
' 9 Déclarations
......
<déclaration N>
% $ ' #' 9 ,
- ' + 3 " 9 DEBUT
' +
- ' + 3 ' 3 "" <instruction 1>
' & & <instruction 2>
.......
Corps de l'algorithme
' &
<instruction P>
% $ ' ( ' +
3 & " & 3 + FIN

6 7
$ $

" "

• <NOM_ALGORITHME> , & ' % & # ' +


& : 0 + " % & # ' '
"" ' & & = '
• <déclaration i> , & " & 3
+ ; # + , % = ' '
<identificateur_variable> : <type_variable> ' + ; . ;' = ' "
- < ' + ' " " + ' '
+ ' ' ;' + ;' >0& ' ;' '
' . & ;' '
;'
% ' + ' '
• <instruction j> , &
? 7 3
5@A$B
% ' ' & '
5@A$B 4 :
8 9
$ $
# $ % #

% $ " ' % , & " #'


C D3 ' " &
- ' ' % $ C ; DE C D
% $ & ! ' ( , )&')*+
% . , ' C + ' ' (
& D 3 "" ' 0 0 ;
- @# ' , ' ' F0G0H0I
- 6 C " "
D ' (
% ,. ' ' ' ' 0
% @# > &E

10 11
$ $

#, ! # -

% ! , "" 3 % . ' ' + ,


' ' 1 - ' ) *C ' D
% , + ' ' - ' ' ' C ' D
1 + - L ' & #' ' # C 0
9 0 G 0 ID
- , #' " J
; % : & C ' ' D
% + ,
- '
% + ,
- 5 ' ;' C & ' ' D Code source en
langage évolué Langage machine
- K "" ' + '' '' ' #

'' +
12 13
$ $
% B ' " ' % B " 3
' 3 #
Compilateur exécution
Exemple.c Exemple.exe Interprétation + exécution
Exemple.java
fichier source fichier exécutable
fichier source
% + , % + ,
% ' ' 3 & # %
% % + ,
% + , % # ' '' 3 '
% " ' 3 "

14 15
$ $

# . %

% B ;' , % J QR )A *'
- ' # 5 7 + & 9 " & ; ( 1 #'
C$: SD
- +
- 9
% @ QRT0 ' ( "
C UH72 D ' U 7
% @# ' , ' + )B *
- 4 0 0 0 0I
- ? A 0M +0 I % ( & '' ' +
- NN0 O0 P + 0 I # ' ( 3

% @ QT 0 & :6 C : 6
D '
" #' ' '
:6 2

16 17
$ $
% !/ 0 !

% $ + , 1 ' + 1 '' % $ ' " # &


' C '' " 0 0 ID ' 0 ' . " '
"
% ( , "" ' ' # % " ' ' '
C ' 0 & 0 ID " 9 C" & D
"" % " 9 & ' # & 0
# " ''
% L , ' . ' ' + . " C' "0 "0 ID +
' ' & " 9
% & "" 9
" ( " "
% , ' :6 2 0 ' ' #
1 . ' ' ; ( C V 0
; ( 1 #' D
% 7 , ' ' ' '
' C " 2. D '
' '
18 19
$ $

% ' + ' 0+ + K &


' +

% # ' ' ' :6 2


$ ' ,
+ '' K '

20
$
" 0

% $ ' " % W +
, % "" + +
-
- #include <stdio.h> /* pour pouvoir lire et écrire */
- void main() /* programme principal */
{
float x; /* déclaration d’une variable x (nombre réel) */
% $ ' ' , printf("Veuillez entrer un nombre réel au clavier: ");
scanf("%f", &x); /* lecture au clavier de la valeur de x */
/* affichage de x : */
#include <stdio.h> /* pour pouvoir lire et écrire */
printf("Vous avez tapé %f", x);
#include <conio.h>
}
int main() /* programme principal */
{
printf("Bonjour tout le monde"); /* écriture à l’écran */
getch();
}
22 23
$ $

# - ! # $

% + + 3 W + % # & " C & + &


' & # & ' " D 3 ( ,
- . 0 "" (
% + + . + &. ) X * C@+ ( ' ' D
% 7 SXYB0 ' #YB C D
0 + . ' , % 7 S2YB0 ' # YB0 ' # YB C D
- C " D - ' C; ' ( D
- ;' C 0 0 ID % 0X C D
% C D

type identificateur; - . "" + , ! 1


type identificateur = valeur; $ ! 0 $
$ $ 2 $
3 4 $ - - 3
Exemples:

float x, y=2.0; /* nombres réels. y a pour valeur % 7 , 9


initiale 2.0 */ 5 6 7 ! " ""
int n; /* nombre entier */

24 25
$ $
# 4 # 4

% ;' C + & D % ;' ' '


+ ' C +
' ' '' + "
+ " 0 ' ' & " D
" + $ % , ' ' 8 9 :8;(< & 3
C D 5 0 + :8;(< &
Z Z C " + % , ' & 9(:=;(< <& 3
' D (:=;(< <&
% , ( ' (<
9 :8;(<8> ) 3 :8;(<8> )

% ? ,
- , C , 2 R[T 3 % + # '
R[RD
DBL_MAX FLT_MAX ( float.hD
- , C D
% ( math.h "
- , C ,2 R T [ T3 R T [ RD
" pow C' D0 sqrt C D0 cos0 sin0 tan0

26 27
$ $

# 4 # 4

% ;' C + & D ;' % # ;' ' ;'


( ( & ' ' ' C D C D
. W + + C Z [ 3 D ' + ' +
' + ' ( +
% $ + 3 Z
% # ' 0 ( ' 9 :::
? ' + +* ++ : : : ><
% $ + 3 T Z C & 232
' ! ::: 2 ' + >= >& : : : ())
= '' ( 6 3 D

28 29
$ $
$$ - -

% \ #+ . ;' 0 ' ' % ;' ; +


& + & ' "" C ED ' '
0 ' ' + +
#' % + " 1 (
% 6 # + ;' "" 0 & ' ' +
& "" E+ 0 & ' 0 +
6 + & ' ' 0 ' ""
& % @# ' ,
- # ' G#, + "
Exemple d’affectation - # 1 , + ' "
int var1=0, var2=3; /*déclarations avec initialisations*/ % @# ' ,
var1=2*var2+1; /* affectation : après ceci var1 vaut 7 */ - ' 0' ' 1 +
Exemple de conversion d’un float vers un int - ' + " + '
int n;
float x=7.6587e2;
n = (int)x; /*après ceci n vaut 765 (arrondi à la partie
entière) */
30 31
$ $

@ - ! @

% + 0 % $ + + ' & # &


"# ;' ' " + ' '
C D % @ 0 + 3 ,
- + O " ,
% 6; # #define nom_constante valeur
<Type> <NomVar1>,<NomVar2>,...,<NomVarN>; % ' ( ' ;'
% # ' , #define PI 3.141592
- ,
% @# ' , const type nom = expression ;
int i, j, k; % 5 ;'
float x, y ; % # ' , const float PI =3.141592
double z=1.5; // déclaration et initialisation
short compteur;
char c='A';

32 33
$ $
@ $ 4 0

% @ 0 ' ' " ' ' ;' % $ #' ' . + 0 +


& + 3 ;' 3 ;' 0 ' ' + 0
5 & # ' + 0 ' + #' '
' " '' ' ! - # ' , 0 0 G 0 N G 2 0I

#include <stdio.h> /* pour pouvoir lire et écrire */ % $ ' ; ' '


typedef int Entier; /* Définition d’un nouveau type Entier */ ' + ' ' = ,
void main() - ' # ' C #, N D
{ - ' ' C #, NND
Entier d, n; - 1 ' F, 0 '
scanf("%d", &n);
d = 2*n;
printf("Le double de %d est %d\n", n, d);
% $ #' " + 0 +
} ' ( ' & +

34 35
$ $

% ' = ' % ,N2G ]C D ,2


0 ' ' # & "" 0
& ' % ' ' + . "' ]

% = ' + ,
- ' , N0 20 G0 0 ] % ;' # ' "" ;&
- ' & "" , E0 NE0 2E0GE0 E + ' ;' ' "
- ' , HH0 ^^0 _
- ' ' , EE0 _E0 `0 a0 `E0 aE
% & ' # '
- ' & , NN0 22 C D &
- ' , ``0 aa0 H0 ^0 b0 c ' C D
- & ' ' , F,0 K "

36 37
$ $
" $$ '

% & ' E "" + #' 3 + `, " 3 `E , " 3


- @# ' , #0;0Kd #E d ;E Rd KE#G;2 d a, ' 3 aE , ' 3
EE , 3 _E , ""
% 3 & "" '' + C " + D
% ' & ' + 0
% 1 "" ' #' + " # +
1 #' + ""
% #' ' + +
% = ' "" 0 & + " 3 #'

- # ' , E 9 E WE C + 3 W E 0 9EW E9D


% @# ' , E 0 ER0 E
b==3 0 (faux)
% + "" 9 + ;' + 0 a!=b 1(vrai)
. ;' ' " C # , + " 0 4*(a<b) + 2*(c>=b) 4
+ ' 1 " D

38 39
$ $

% - AA BB

% AA , @B BB , =$ C, % ( ' +

% HH + # ' + C+ D % HH , + + + C + " #0
+ HH + " #D

% ^^ + & ' + C+ D % ^^ , + + " # C + + 0


+ ^^ + + D

% + ' , + % @# '
' 3+ ' 3" # - " CC _E D HH C EE DD , ' + +
- @# ' , - " CC aE D HH C C D ` 'DD , `
% HH
%_ R % & . & & + & +
'' '

40 41
$ $
!

% ' NN 22 ' ' % ' 3 ,


' + 1 9 % H , @B ^ , =$ c , =$ # " b,
' % ' ;' ' 1 ""
% ' "" ' ( + 1 + 3 +
1 #' + 1 ' ' ( '
% W E NN C' 2 D "" 1 + 3W b1 b2 ~b1 b1&b2 b1|b2 b1^b2
' ( CW E NN d WE d E N dD
1 1 0 1 1 0
% W E NN C' 2 D 1 ' ( ""
+ 3 W CW E NN d E N dWE dD 1 0 0 0 1 1
0 1 1 0 1 1
% @# ' , 0 0 1 0 0 0
% E d E NN 2 d + [ +
% E d E NN 2 d + [ +
% 7 , ' & ' 22 @# , E 0 QE H QE ET0 ^QE E

42 43
$ $

! !

% # # ' , % 1 3 ' 3
aa , 3 `` , 3 '
% & ' & 9 3 & ' - 1 3 0 '
+ ' '
% 5 1 3 ' 3 - 1 ' ' & ' C
' ' + ' ' " ' D
'

% @# ' , % @# ' ,
char x=14; (14=00001110) 14<<2 = 00111000 = 56 char x=14; (14=00001110) 14>>2 = 00000011 = 3
char y=-7; (-7=11111001) -7<<2 = 11100100= -28 % 7 , 3 C aa WD ' 3
% 7 , 3 ' C " + ( '
D3 ' '

44 45
$ $
" $$ ! $ D 4 E F

% 6 ' ' # #' #' #' % ' & "" + #' "
& #' exp1= exp1 op exp2 ' & ;' & #'
" J + " exp1 op= exp2 - 6; # , C` ;' aD ` #' a
- @# ' ,

% =' , int n, p ;
+= -= *= /= %= (double) (n / p); + & G
<<= >>= &= ^= |= % 7 , + C D " ' (
(double) (n/p) (double) n / p (double) (n) / (double) (p)

% @# ' ,
a=a+b s’écrit : a+=b % @# ' ,
float n = 4.6, p = 1.5 ;
n=n%2 s’écrit : n%=2
(int) n / (int) p = 4 / 1 = 4
x=x*i s’écrit : x*=i (int) n / p = 4 / 1.5 = 2.66
p=p>>3 s’écrit : p>>=3 n / (int) p = 4.6 / 1 = 4.6
n / p = 4.6 / 1.5 = 3.06

46 47
$ $

EHF % EF

% 6; # , exp1 ? exp2 : exp3 % $ , ' ' 2 #'


– exp1 + 0 + & exp2 # 0 #'
exp3

% + 3
% @# ' , max = a > b ? a : b;
- 6 a "" 3 # #' & 232
"" % + & #' ( 2 #'

% @# ' , a>b ? i++ : i--; % @# '


- 6 a i++ , i + j; + NN N9 C +
D
i++ , j = i + k , a + b; + & #'
N
for (i=1 , k=0 ; … ; …) { }

48 49
$ $
-

% 6; # , sizeof (<type>) ou sizeof (<variable>) % $ #' + ' ( '


& + '
- @# ' ,G ' ' N0 N GR+
% 4 1 ;' 1 +
% ' + '
' '
% @# '

int n;
% ' . . +
printf ("%d \n",sizeof(int)); // affiche 4 ' 5 '' ( & +
printf ("%d \n",sizeof(n)); // affiche 4 "( # ' , ] G +

% 7 , + # ' (
' ' 3 "" ' @#, C N D G R
+

50 51
$ $

52
$
# " $ $ EF

% & ' 3 % " ' " ' "" 3 &


+ & # 0 + +
- 5 ' 3 & & & #'
+ + ' & ' % 6; # , printf("format", expr1, expr2, …);
'
– expr1,… , + #'
- 5 & 0 & ' '
+ 3 '
+ 3 & "" 3
– format , e ( '
& C + " D
% #
% ( <stdio.h>
% & '' C>f &0 >f &0 ID
" % ' " " , # ( '
& , ; ]0 " & ""
– printf() " % 7 , ' " "
– scanf() " . & #' _

54 55
$ $

$ $ % "

% 1 "" # ' . ! 3 1
Symbole Type Affichage 1 '' ,
%d ou %i int Entier relatif %f , +
%f , K
%u unsigned int Entier naturel non signé
% ff , W CfD
%c char Caractère
% f& , ' '
%o int Entier sous forme octale % fg ,
%x ou %X int Entier sous forme hexadécimale %@ I
%f float, double Réel en notation décimale
%e ou %E float, double Réel en notation exponentielle
%s char* Chaîne de caractères

56 57
$ $
0 $EF 0 $EF

#include <stdio.h> #include <stdio.h>


void main() void main()
{ {
int i=1, j=2, N=15; double x=10.5, y=2.5;
char c='A' ; printf("%f divisé par %f égal à %f \n", x, y, x/y);
printf("la somme de %d et %d est %d \n", i, j, i+j); printf("%e divisé par %e égal à %e \n", x, y, x/y);
printf("N= %x \n" , N); }
printf("le code Ascii de %c est %d \n", c, c);
} % ' + "" ,
10.500000 divisé par 2.500000 égal à 4.200000
1.050000e+001 divisé par 2.500000e+000 égal à 4.200000e+000
% ' + "" ,
la somme de 1 et 2 est 3 % 7 , ' +
N=f ;' 0 "
le code Ascii de A est 65 ' " ]" ]

58 59
$ $

7 % $$ 7 % $$

% " 0 "" ' % 0 ' '


+ ' ( + 3 "" "" ' (
% & "" ' ' ( '
] ' ( 3 % ' ' " "# 3 #
' 3 + '
% @# ' ,' "Cg] g0 Dd '
% E bb Cb , ' D % @# ' ,
% E [ [ printf("%f", 100.123); 100.123000
% ' "Cg] Sg0 Dd bbRA printf("%12f", 100.123); ~~100.123000
printf("%.2f", 100.123); 100.12
% ' "Cg] #g0 Dd bbR printf("%5.0f", 100.123); ~~100
printf("%10.3f", 100.123); ~~~100.123
printf("%.4f", 1.23456); 1.2346

60 61
$ $
# $ $ EF 0 $EF

% " " ' 3 ' #include <stdio.h>


+ void main()
{
% 6; # , "Cg" g0 ? 0 ? 0 IDd
int i , j;
- 4 , " 0 . scanf("%d%d", &i, &j);
' ' " printf("i=%d et j=%d", i, j);
- ? 0 ? 0I , + # }
& & +
' + ' H % ' ' #
+ "" 3 &
% 7 ,' ;' 0 "
' " ] 0] 0] 0] 0]#

62 63
$ $

0 $EF

#include <stdio.h>
void main()
{
float x; !
double y;
scanf("%f %lf", &x, &y);
printf("x=%f et y=%f", x,y);
}

% ' ' '


+ "" 3 &
% 7 , ' ;' 0
" ] ]" '
;' 0 " ] ] "

64
$
I #" J E $J F

% ! " " J + % 6; # ,
"" @ si(expression) if (expression)
1 # 1 3 + bloc-instruction1 bloc-instruction1
1 #' sinon else
bloc-instruction2 bloc-instruction2
% = ,
- - C D , ' & "" - ! 9 ' .
# 3 ' "" + ' ' 2+ & '
C+ 1 #' D @ 0 ' hi
, $J 3
- 0 + 0 + C+ ""
- - C D,' ' D0 ! 9 ( # 6 "
' " & " C+ D ! 9 ) #
' ,3 0 J3 $
% ' " + 6& &; '
3 " 0
' " ,
if (expression) bloc-instruction1
66 67
$ $

$J 0 ! $

ALG_MAX float a, b, max;


% = ' ' "I
VAR if (a > b) % ' 3 " 0' # ' ,
a, b, max: réels max = a; if (N>0)
si (a > b) else if (A>B)
max <- a max = b; MAX=A;
sinon else MAX=B;
max <- b C ' , :E L S' + AD
if (N>0)
if (A>B)
ALG_PARITE int a;
MAX=A;
VAR if ((a%2)==0)
else MAX=B;
a: entier printf("%d est paire", a);
si(a MOD 2 = 0) else C ' , :E L S ' D
Ecrire("a est paire"); printf("%d est impaire", a); % @ 9
sinon ' ( ' ' C & & '
Ecrire("a est impaire"); 9 D
68 69
$ $
! $ #" " 3

% ,' + j ' " % 3 #


' & 0 + # + & #' . ;'
if(a<=0){ % ; # ,
if(a==0) switch (expression) {
printf("a est nul "); case expression_constante_1 : instructions_1; break;
else case expression_constante_2 : instructions_2; break;
printf(" a est strictement négatif "); …
}
case expression_constante_n : instructions_n; break;
else
default : instructions;
printf(" a est strictement positif " );
}
% " & ' ,
if (N>0){ % ! ! . #'
if (A>B) (
MAX=A; % ! ' . ' '
} % ' ' + ' "
else
MAX=B;
70 71
$ $

K 3 3 0 (

% + #include <stdio.h>
% + 3 ! !0 void main()
{
3 #
int a;
! ' printf("Donner un entier: ");
- = # + 9 &3 scanf("%d", &a);
" 9 &3 WC " switch(a){
" D case 1 : printf("Un");
break;
% + 1 #' 1 3 case 2 : printf("Deux");
#' break;
- 6 # 0 # case 3 : printf("Trois");
+ break;
- 6 & # default: printf("Autre");
}
}

72 73
$ $
3 0 ) # ! 3

#include <stdio.h> Tant que (condition) répéter while (condition)


void main() { {
{ instructions instructions
char c; } }
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o': % 5 " 1 "" +
case 'u': 1 ' 0 " 0 ' 9
case 'y': printf("voyelle\n"); break ; 1 #
default : printf("consonne\n");
}
}

74 75
$ $

# ! J3 # ! 3 0

Répéter do % $ ' '


{ { : 3 : '
instructions instructions
} tant que (condition) } while (condition);

#include <stdio.h>
void main()
{
% 5 #" "" ' ( ' int i = 0, som = 0;
0 # " while (som <=100){ do{
i++; i++;
som += i; som += i;
} } while (som <=100);

printf ("La valeur cherchée est N= %d\n", i);


}

76 77
$ $
# ! J3 0 # ! $

% ! 1 + 9 &3 pour(expr1; expr2; expr3) répéter for(expr1; expr2; expr3)


+ + { {
instructions instructions
} }
#include <stdio.h>
void main()
{ % 1 #' + "
int n; 1 # @ "" &
do{
printf ("Entrez une note comprise entre 0 et 20: "); % 1 #' + + '
scanf("%d",&n); @
} while(n < 0 || n > 20); % 1 #' + ' ( ' @
} ' "

78 79
$ $

# ! $ % # ! $ 0

for(expr1; expr2; expr3) expr1; % 3 ' <


{ while(expr2){ ' "
instructions instructions
} expr3;
} #include <stdio.h>
void main()
% @ ' 0 + ' {
0 ' ' + float x, puiss;
int n, i;
printf ("Entrez respectivement les valeurs de x et n: ");
scanf ("%f %d" , &x, &n);
for (puiss =1, i=1; i<=n; i++)
puiss *= x;
printf ("%f à la puissance %d est égal à: %f", x,n,puiss);
}

80 81
$ $
#" ! 1 #"

% & W' . % & ' .


C" 0 V 0 V D C" 0 V 0 V D @ '
% @ ' & . & & ' 3
' 3 ' ( & +
% @ 0 W " &3 #include <stdio.h>
void main()
'
{
#include <stdio.h>
int i;
void main()
{ for(i=1; i<=10; i++){
int i,j; if(i == 5) continue;
for(i=0;i<4;i++){ i=0,j=0 printf("%d " ,i);
for (j=0;j<4;j++){ }
if(j==1) break;
i=1,j=0
}
printf("i=%d,j=%d\n",i,j); i=2,j=0
} i=3,j=0 1 2 3 4 6 7 8 9 10
}
}

82 83
$ $

% H

% 6 '' 1 + + 1
' # " # ' ,
1 ; ' 3

# % ; ' 3
+ 0' # ' 5( J 5 < ' ( 0
$ %%% ' "
nbre 0
Si (N1 >10) alors nbre nbre+1 FinSi
......
Si (N30>10) alors nbre nbre+1 FinSi

% 1 3 __
% Y 0 ' "" '
+
'' !

85
$
L ! 0 L ! 0 %

% $ ! 1 . ;' % 1 ( 3 " ; 1
' " # ' 0 MN + 1

% $ + ( ' 1
' 1 % @ &0 ' 5 0 MN
+ 1 N

% 1 1 "" ' 4
C D % $ + # 1 ' ;
- @ ' , W " J '

+ ! " M N 4
- @# ' ,
+ ! M <N
<N
% = ' " # ;' , # 1 0
0 ( 0 0I

86 87
$ $

L ! 0 0 L ! 0 $$

% 6 "" 1 ,
% 1 ; ' 3
variable i: entier
+ #0 ' ,
n : entier
tableau T : réel
Variables i ,nbre : entier
Début
tableau notes[30]
] : réel
n <- 30
Début
Pour i allant de 0 à n-1 faire
nbre 0 Ecrire ("Saisie de l'élément ", i + 1)
Pour i allant de 0 à 29 faire Lire (T[i] )
Si (notes[i]
notes[i] >10) alors
FinPour
nbre nbre+1
FinSi
FinPour 3 2 "
Ecrire ("le nombre de notes supérieures à 10 est : ", nbre) @ CgBkg0 0 gl Eg0 Bk lD
Fin K
K

88 89
$ $
L ! 0 L ! 0O 0
% 5 , % ' ' #
Type identifacateur [dimension]; + ' ' 0
' # ' ' '
% @# '
int tab [10];
float notes[30]; % @ ' 0 3 # ,

+ ! " M (N M )N 4
% L '
- @# ' ,
tab[2] = 5;
notes[29] = 17.5;
+ ! M NM8
NM8N

printf("tab[1] = %d", tab[0]); % M NM/N ' 1 3 & + 3


tab[i] = tab[j]*2; & 9

90 91
$ $

L ! 0O 0

% 5 ,
Type identifacateur [dimension1][dimension2];
% @# '
int matrice[3][4];

% L '
matrice[0][0] = 5;

printf("matrice[1][1] = %d", matrice[0][0]);

92
$

Vous aimerez peut-être aussi