Enregistré dans : Non classé
/* ici je n’ai pas fais de bibliothéque.*/
#include
#include
#include
int voyelle (char * tab)
{
int voyelle, taille,i; //dec.ress
taille=strlen(tab);
voyelle=0;
for(i=0;i
if((tab[i]=='a') || (tab[i]=='e') || (tab[i]=='i') || (tab[i]=='o') || (tab[i]=='u') || (tab[i]=='y'))
{
voyelle ++; //si la lettre est une voyelle, on incrémente voyelle qu'on retournera au main
}
}
return (voyelle);
}
void mirroir(char * tab1)
{
char * tab2;
char * tab3;
short int taille1, i,k;
taille1=strlen(tab1);
tab2=(char *) malloc (taille1 * sizeof(char)); //on alloue la deuxieme chaîne
k=taille1;
for(i=0;i
tab2[i]=tab1[k]; //on fait l'effet du mirroir
k--;
}
tab3=(char *) malloc (((2*taille1)+3) * sizeof(char));
// on met les deux tableaux dans tab3
strcpy(tab3,tab1);
tab3[taille1+1]=' ';
tab3[taille1+2]=':';
tab3[taille1+3]=' ';
strcat(tab3,tab2);
for(k=0;k<((2*taille1)+3);k++)
{
printf("%c",tab3[k]);
}
}
int consonne(char * tab)
{
int consonne, taille,i;
taille=strlen(tab);
consonne=0;
for(i=0;i
if((tab[i]!='a') && (tab[i]!='e') && (tab[i]!='i') && (tab[i]!='o') &&(tab[i]!='u') && (tab[i]!='y'))
{
consonne ++; // si la lettre n'est pas une voyelle on incrémente consonne et on le retournera dans le main
}
}
return (consonne);
}
int main()
{
char * matrice;
int k,i,nbvoy,nbcons; //dec.ress. statique
{
char tableau[100]={0};/dec.ress. dynamique
printf("Entrez votre phrase\n");
gets(tableau);
k=strlen(matrice);
matrice=(char*) malloc ((k)*sizeof(char));
strcpy(matrice, tableau);
} /* la fermeture d'accolade permet l'allocation dynamique du tableau
printf("\n\nVotre chaîne est :\n");
puts(matrice); //affichage de la matrice
nbvoy=voyelle(matrice); //appel de la fonction voyelle
if (nbvoy>1) printf(”Il y a %d voyelles\n”,nbvoy);
else printf(”Il y a %d voyelle\n”,nbvoy); //affichage en fonction du nombre de voyelle
mirroir(matrice); //appel de la procédure mirroir
nbcons=consonne(matrice); //appel de la fonction consonne
if(nbcons>1) printf(”\nil y a %d consonnes”,nbcons);
else printf(”\nil y a %d consonne”,nbcons); //affichage en fonction du nombre de consonne
}
Pas de commentaire so far
Leave a comment
Laissez un commentaire