1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
int code ;
char paysdest[20];
float prix;
}vol;
vol* chargement(int n)
{
vol* t;
int i;
t=(vol*)malloc(n*sizeof(vol));
for(i=0;i<n;i++)
{
printf("vol %d\n ",i);
printf("code :\n");
scanf("%d",&(t+i)->code);
printf("pays de destination:\n");
scanf("%s",&(t+i)->paysdest);
printf("prix:\n");
scanf("%f",&(t+i)->prix);
}
return (t);
}
void afficher( vol* t , int n)
{
int i;
for(i=0;i<n;i++)
{
printf("affichage de %d vol\n",i);
printf(" code %d \n",(t+i)->code);
printf(" pays destination %s\n",(t+i)->paysdest);
printf(" prix %f\n",(t+i)->prix);
}
}
int compter(vol* t, int n, char dest[20])
{
int nb=0,i;
for(i=0;i<n;i++)
{
if(strcmp((t+i)->paysdest,dest)==0)
{
nb=nb+1;
}
}
return nb;
}
void main()
{
int n,nb;
vol*t;
char pays[20];
do
{
printf("donner le nombre de vol \n");
scanf("%d",&n);
}
while((n<=2)||(n>=10));
t=chargement(n);
printf("donner un pays \n");
scanf("%s",&pays);
nb=compter(t,n,pays);
printf("le nombre de vol correspond a ce pays est %d \n",nb);
afficher(t,n);
getch();
} |
Partager