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
| int Trouver_capitales(struct geo t[])
{int i,j,w,compteur;
char x[20],y[20],z[20];
compteur=0;
/*tri du tableau*/
for ( i=0 ; i<nb_v ; i++ )
for ( j=i+1 ; j<nb_v ; j++ )
if ( strcmp ( t[i].pays , t[j].pays )==0 )
{ strcpy(x,t[j].pays);strcpy(y,t[j].ville);strcpy(z,t[j].continent);w=t[j].nhab;
strcpy(t[j].pays,t[i+1].pays);strcpy(t[j].ville,t[i+1].ville);strcpy(t[j].continent,t[i+1].continent);t[j].nhab=t[i+1].nhab;
strcpy(t[i+1].pays,x);strcpy(t[i+1].ville,y);strcpy(t[i+1].continent,z);t[i+1].nhab=w;
}
/* afficher la plus grande ville de chaque pays du continent africain */
for ( i=0 ; i<nb_v ; i++ )
{ if ( strcmp(t[i].continent,"afrique")==0 )
{ for ( j=i+1 ; j<nb_v; j++ )
{ if (( strcmp (t[i].pays,t[j].pays)==0 )&&(t[i].nhab<t[j].nhab ))
{ i=j;
}
else
{i=j;
j=nb_v;
printf(" - %s ",t[i].ville );
compteur++;
}
}
}
}
return compteur;
} |