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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/**Directives de précompilations-----------------------------------------**/
#include <math.h>
#include <stdio.h>
#include <myconio.h>
/**definition de variable --------------------------------------------------**/
#define TAILLE 600
/**Programme principal --------------------------------------------------**/
void analyse_montees_descentes(int*,int, int*,int*,int*,int*,int*,int*,int*) ;
void min_max (int*,int,int*,int*);
/**prototype des Fonctions-----------------------------------------------**/
int main()
{
/** Déclarartions ---------------------------------------------------**/
int altitudes[TAILLE] =
{100, 130, 160, 210, 205, 200, 205, 160, 110, 120, 115, 90};
int taille,
d_montee=0, d_descente=0, d_plat=0, /*Distances*/
h_montee=0, h_descente=0; /*Cumul des dénivelés*/
int MAXVAL=0, MINVAL=altitudes[0];
taille = 12;
/** Traitement ------------------------------------------------------**/
analyse_montees_descentes(altitudes,taille,&d_montee,
&d_descente,&d_plat,&h_montee,&h_descente,&MAXVAL,&MINVAL) ;
/** Encodage --------------------------------------------------------**/
/** calculs ---------------------------------------------------------**/
min_max(altitudes,taille,&MAXVAL,&MINVAL);
/** Affichages ------------------------------------------------------**/
printf("Analyse de l'etape\n\n");
printf("Montee totale de %d metres sur %d km\n",h_montee, d_montee);
printf("Descente totale de %d metres sur %d km\n",
h_descente,d_descente);
printf("Plat sur %d km\n", d_plat);
return 0;
}
/**-----autres fonctions -----**/
void min_max(int *altitudes, int taille,int *maxi, int *mini)
{
int indice=0 ;
while (indice<taille)
{
if (altitudes[indice]>*maxi)
*maxi = altitudes[indice];
if(altitudes[indice]<*mini)
*mini=altitudes[indice];
indice++;
}
}
void analyse_montees_descentes(altitudes,taille,*d_montee,
*d_descente,*d_plat,*h_montee,*h_descente,*maxi,*mini)
{
int indice;
/**si ça monte**/
for (indice=0;indice>taille;indice++)
{
if (altitudes[indice]>altitudes[indice-1])
{
if((altitudes[indice]-altitudes[indice-1])<((*maxi-*mini)*0.1) )
*d_plat++;/**on incrémente les kilometres de plat**/
else
*h_montee=*d_monte+altitudes[indice]-altitudes[indice-1];
*d_montee++;
}
else (altitudes[indice]>=altitudes[indice-1])
{
if((altitudes[indice]-altitudes[indice-1])<((*maxi-*mini)*0.1) )
*d_plat++;/**on incrémente les kilometres de plat**/
else
*h_descente=*h_descente+altitudes[indice]-altitudes[indice-1];
*d_descente++;
}
}
} |
Partager