Initiation Au Langage C

Télécharger au format pptx, pdf ou txt
Télécharger au format pptx, pdf ou txt
Vous êtes sur la page 1sur 16

INITIATION AU

LANGAGE C

Initiation à la programmation
GENERALITES
La programmation est une branche de l’informatique qui sert à créer des programmes. Tout ce
que vous possédez sur votre ordinateur est un programme : votre navigateur Internet (Internet
Explorer, Firefox, Opera, etc.), votre système d’exploitation (Windows, GNU/Linux, Mac OS X, etc.) qui
est un regroupement de plusieurs programmes appelés logiciels, votre lecteur MP3, votre logiciel de
discussion instantanée, vos jeux vidéos, etc.

Un langage de programmation permet de traduire l’algorithme dans un langage compréhensible


par l’ordinateur. Il existe des milliers de langages de programmation (ASP. NET, C, C++, C#, Delphi,
HTML, Java, JavaScript, Perl, PL/SQL, PHP, Python, R, SQL , Swift, Transact-SQL, Visual Basic, VBA,
VBScript, Wlangage, Etc. ).

Le langage C
Il a été créé en 1972. Le langage C est une évolution du langage B.
Le langage C est encore très utilisé aujourd'hui (dans le top 10 des langages de programmation les
plus utilisés).

Quelques outils pour écrire des programmes en langage C


 Code::Blocks (Windows, Mac OS, Linux)
 Dev C++ (Windows)
 Visual C++ (Windows)
 Xcode (Mac OS seulement)
Initiation à la programmation
DECLARATION DES BIBLIOTHEQUES ET SYNTAXE D’UN PROGRAMME
1. Déclaration d’une bibliothèque :
Le langage C comprend un ensemble de bibliothèques. Une bibliothèque contient à son tour un
ensemble de fonctions prédéfinies.

Pour ajouter une bibliothèque :


#include<Nom de la bibliothèque>

Exemple :
#include<stdio.h>
Cette bibliothèque contient les fonctions printf et scanf

2. Syntaxe d’un programme en C


/*Déclaration des bibliothèques*/
main()
{
/*Déclaration des variables*/
/*Instructions*/
}

Initiation à la programmation
TABLEAU DE CONVERSION

Algorithme Langage C
Déclaration de variables
Nom_Variables : Types_Variable Type_Variables : Nom_Variables ;
Ex : Ex :
Nombre2 : Entier int : Nombre2;
Instructions
Afficher printf
Ex : Ex :
Afficher(“Entrer un nombre”) printf(“Entrer un nombre”);
Saisir scanf
Saisir(Nombre2) scanf(“Code_Type_Variable”,&Nom_
variable);
scanf(“%d”,&Nombre2);

Initiation à la programmation
TABLEAU DE CONVERSION
Algorithme Langage C
Types de variables Codes du type
Entier int %d
Réel float %f
Caractère char %c
Chaîne de caractère char %s

Opérateurs de calcul Opérateurs de comparaison


Algorithme Langage C Algorithme Langage C
 = = ==
+ + <> !=
- - > >
* * >= >=
/ / < <
<= <=

Initiation à la programmation
EXEMPLE D’UN PROGRAMME : SOMME DE DEUX NOMBRES

• main() : est la fonction principale d’un programme écrit en langage c


• \n : permet de renvoyer à la ligne

Initiation à la programmation
TABLEAU DE CONVERSION
Algorithme Langage C
Structure Conditionnelle SI
Si <condition> if(Conditions) Exemple :
alors { if(Nombre == 0)
Instructions Instructions; {
[sinon } printf(“Impossible de faire la
instructions] else division”);
Fsi { }
Instructions; else
Exemple : } {
division = nombre1 +
nombre2 ;
}

Initiation à la programmation
TABLEAU DE CONVERSION
Algorithme Langage C
Structure Répétitive Pour
Pour variable  for(Initialisation, Exemple :
valeur_initiale à Conditions, for(i =0;i<=10;i++)
valeur_finale Faire Incrementation) {
Instructions { printf(“%d”,i);
FPour Instructions; }
}

Initiation à la programmation
TABLEAU DE CONVERSION
Algorithme Langage C
Structure Répétitive Tant que…Faire
Tant que <condition while(Conditions) Exemple :
(vraie)> faire { i = 0;
Instructions Instructions; while(i<=10)
FTQ } {
printf(“%d”,i);
i++;
}

Initiation à la programmation
TABLEAU DE CONVERSION
Algorithme Langage C
Structure Répétitive Répéter…Jusqu’à
Répéter do Exemple :
Instructions { i = 0;
Jusqu’à <condition> Instructions; do
} {
while(Conditions); printf(“%d”,i);
i++;
}
while(i<=10)

Initiation à la programmation
TABLEAU DE CONVERSION
Algorithme Langage C
Création d’un tableau à une dimension
Tab : Tableau[1..5] De Type_tableau : nom du Exemple : Déclaration d’un tableau de
entier tableau[taille] ; 3 valeurs de type Entier
Lors de la creation d’un tableau,
il faut une variable qui sera int tab[3]i;
initialisée à 0. L’indice d’un for(i=0, i<3,i++)
tableau commence toujours à
{
partir de 0.
La saisie des valeurs se fait avec printf(“Saisir le N°”,i+1);
la boucle for scanf(“%d”,&tab[i]);
}

Initiation à la programmation
CORRECTION SOMME + DIVISION DE DEUX NOMBRES ENTIERS

Initiation à la programmation
CORRECTION CALCUL DU CARRE D’UN NOMBRE

Initiation à la programmation
ALGORITHME SOMMES DE DEUX NOMBRES AVEC LE LANGAGE PYTHON
Algorithme PYTHON

Algorithme : Somme2Nombres Programme :


VARIABLES
nombre1,nombre2,somme : entier
DEBUT
Afficher(“Entrer un nombre”)
Saisir(nombre1)
Afficher(“Entrer un deuxieme
nombre”)
Saisir(nombre2) Résultat :
somme  nombre1 + nombre2
Afficher(“La somme est :”,somme)
FIN

Initiation à la programmation
ALGORITHME SOMMES DE DEUX NOMBRES AVEC LE W-LANGAGE
Algorithme W-LANGAGE

Algorithme : Somme2Nombres Programme :


VARIABLES
nombre1,nombre2,somme : entier
DEBUT
Afficher(“Entrer un nombre”)
Saisir(nombre1)
Afficher(“Entrer un deuxieme Résultat :
nombre”)
Saisir(nombre2)
somme  nombre1 + nombre2
Afficher(“La somme est :”,somme)
FIN

Initiation à la programmation
TOP 10 DES LANGAGES DE PROGRAMMATION EN 2020

1. Java
2. Langage C
3. Python
4. C++
5. C#
6. Visual Basic.Net
7. Javascript
8. PHP
9. SQL
10.Langage Go

Vous pouvez retrouver l’article sur ce lien :


https://bertrandbourgy.com/top-20-langages-de-programmation-en-2020/

Initiation à la programmation

Vous aimerez peut-être aussi