COURS
CHAPITRE :
1
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
1 Introduction
2
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
<suite d’instructions>
}
Exemple:
/* suite d’instructions */
if (A > B) maximum = A;
else maximum = B;
/* renvoi du résultat */
return (maximum);
}
3
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
REMARQUES :
Exemple :
4
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
Syntaxe:
<Type Résultat> <Nom Fonction>
(<TypeP1> [<NomP1>], <TypeP2> [<NomP2>], ...);
Toute fonction doit être déclarée avant d’être utilisée (sauf la fonction
main, on peut ne pas la déclarer )
Exemple:
#include <stdio.h>
void Rectangle (int lg, int ht );
void Ligne (int lg);
void main ( )
{ int L, H;
printf (“Donner la longueur :\n “); scanf (“%d“, &L);
printf (“Donner la hauteur :\n “); scanf (“%d“, &H);
Rectangle (L, H);
5
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
6
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
Exemple:
7
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
Exemple:
void main ( )
{ int C, A, B ;
A = 3;
B = 7;
C = max (A, B);
...
}
8
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
6 Passage de paramètres
Exemple:
9
Cours : Algorithmique & Programmation C Chapitre : Les Fonctions en Langage C
Exemple:
void permuter (int *A, int *B) ;
void main ( )
{ int x, y;
x = 3;
y = 4;
permuter (&x, &y);
/* x = 4 et y = 3, x et y changent de valeurs */
...
}