Académique Documents
Professionnel Documents
Culture Documents
SERIE 2 - Solutions
Exercice 1 :
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define NMAX 10
int dim_t()
{
int i;
do
{
printf(" Donner le nombre de pharmacies : ");
scanf("%d",&i);
}
while(i<=0||i>NMAX);
return i;
}
typedef struct
{
char pha[20],pat[10];
int dis;
} pharmacie;
1
}
}
/****************ROGRAMME PRINCIPAL***************/
int main()
{
pharmacie ph[NMAX];
int N;
N=dim_t();
lireInfos(ph,N);
affichage(ph,N);
recherche(ph,N);
getch();
}
2
Exercice 2 :
#include <stdio.h>
#include<stdlib.h>
#define MAX_P 30
typedef struct
{
char nom[20];
char prenom[30];
int dejeuner; //0=non, 1=oui
int diner; //0=non, 1=oui
int hotel; //1=pas d'hotel, 2=2etoiles, 3=3etoiles
int seul; //0=non, 1=oui
} participant;
int montant(participant p)
{
3
int total=0;
if(p.dejeuner==1)
total +=50;
if(p.diner==1)
total +=80;
if(p.seul==0)
total*=2;
if(p.hotel==2)
total+=150;
if(p.hotel==3)
total+=200;
return total;
}
main()
{
int montTot=0, nP; //montant total
tabPart tabp;
printf("Donnez le nombre des participants \n");
scanf("%d", &nP);
system("pause");
}
4
Exercice 3 :
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct {
int code;
char nom[20];
float prix;
} Article;
5
(*n)--;
//i--; si le code n'est pas unique
}
}
}
main(){
Article t[30], * a;
int n, choix, code;
do{
//Menu
puts("-------------Menu-------------");
puts("1: Lire les articles");
puts("2: Afficher les articles ");
puts("3: Trier les articles du plus cher au moins cher");
puts("4: Supprimer un article");
puts("5: Quitter le programme");
puts("Tapez votre choix :");
scanf("%d", &choix);
switch(choix){
case 1:
printf("Donner le nombre d'articles: ");
scanf("%d", &n);
lireArticle(t, n);
break;
6
case 2:
afficherArticle(t,n);
break;
case 3:
triByPrix(t,n);
break;
case 4:
printf("Entrer le code de l'article a supprime: ");
scanf("%d", &code);
supprimerArticle(t, &n, code);
printf("Liste des articles apres suppression de l'article %d :
\n", code);
afficherArticle(t, n);
break;
case 5:
printf("Fin du programme\n");
break;
default:
printf("Choix invalid!\n");
}
}while(choix != 5);
}
Exercice 4 :
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAXNOTES 10
typedef struct
{
int jour;
char mois[10];
int annee;
} DATE;
typedef struct
{
char nom[10];
char prenom[10];
DATE date_naissance;
char formation[3];
7
float notes[MAXNOTES];
int nbnotes;
} FICHE;
int main(void)
{
int nbNotes;
FICHE *etd_fiche;
etd_fiche = (FICHE *) malloc(sizeof(FICHE));
RemplirFiche(etd_fiche);
printf("Quel est le nombre de notes que vous souhaitez ajouter : ");
scanf("%d",&nbNotes);
AjouterNote(etd_fiche, nbNotes);
AfficherFiche(etd_fiche);
printf("\n La moyenne est : %f",moyenne(etd_fiche));
return 0;
}
8
printf("Entrez la note %d : ",i);
scanf("%f", &fiche->notes[i]);
fiche->nbnotes++;
}
}
else
printf("\n <---- Impossible d'ajouter une note ---->\n");
return som/fiche->nbnotes;
}