U3F1ZWV6ZTMzNjI4NTk3OTIwNjE0X0ZyZWUyMTIxNTgyNzQ2MjExOQ==

Langage C TP 4 Chaines de caractères et tableaux

"pour telecharger la serie "click ici





:Exercice 3
.3  Ecrire une fonction qui supprime la lettre ’a’ dans une chaine de caractère


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void supprimer(char *text){
int i,l,j;
l=strlen(text);
for(i=0;i<=l;i++){
if(text[i]=='a'){
for(j=i;j<=l;j++){
text[j]=text[j+1];
}
i--;
}
}puts(text);
}
int main(){

char text[100];
puts("Saisir votre text:");
gets(text);
supprimer(text);
return 0;
}





:Exercice 4

Ecrire une fonction qui vérifie si une chaine de caractères passée en paramètre est un palindrome(lisible dans les deux sens, “Esope reste ici et se repose“)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char mot[100];
int i,tab[100],longueur=0;
int t=0;

printf ("Tapez un mot: ");
scanf ("%s",tab);
for (longueur=0; longueur<=strlen(mot)/2; longueur++)
{
if (tab[longueur]!=tab[strlen(mot)-i])
t=1;
}
if(t==0)

printf ("c'est un palindrome\n");
else {
printf ("ce n'est pas un palindrome\n");
}

return 0;
}



:Exercice 5

Ecrireunprogrammequidemandeàl’utilisateurdesaisirunverbedupremiergroupe. Vous devez tout d’abord vérifier que le verbe se termine bien par “er”. Ensuite vous devez afficher la conjugaison de ce verbe au présent de l’indicatif. Exemple :
Saisir un verbe du premier groupe: chanter
Je chante
Tu chantes
 Il chante
Nous chantons
 Vous chantez
Ils chantent











#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {

    char VERB[20];
    char AFFI[30];
    int L;
    printf("entrer un verbe du premier groupe : ");
    scanf("%s",VERB);

    L = strlen(VERB);
    if ((VERB[L-2]!='e') || (VERB[L-1]!='r')) printf("Ce n'est pas un verbe du premier groupe.!");
    else {
            VERB[L-2]='\0';
     
             AFFI[0]='\0';
            strcat(AFFI, "Je ");
            strcat(AFFI, VERB);
            strcat(AFFI, "e\n");
            printf(AFFI);
             AFFI[0]='\0';
            strcat(AFFI, "Tu ");
            strcat(AFFI, VERB);
            strcat(AFFI, "es\n");
            printf(AFFI);
             AFFI[0]='\0';
            strcat(AFFI, "Il ");
            strcat(AFFI, VERB);
            strcat(AFFI, "e\n");
            printf(AFFI);
             AFFI[0]='\0';
            strcat(AFFI, "Nous ");
            strcat(AFFI, VERB);
             if (VERB[L-3]=='g')
{
             strcat(AFFI, "eons\n");
             printf(AFFI);
             AFFI[0]='\0';
}else
            strcat(AFFI, "ons\n");
            printf(AFFI);
             AFFI[0]='\0';
            strcat(AFFI, "Vous ");
            strcat(AFFI, VERB);
            strcat(AFFI, "ez\n");
            printf(AFFI);
             AFFI[0]='\0';
            strcat(AFFI, "ils ");
            strcat(AFFI, VERB);
            strcat(AFFI, "ent \n\n");
            printf(AFFI);
            }
return 0;
تعليقات
ليست هناك تعليقات
إرسال تعليق

إرسال تعليق

الاسمبريد إلكترونيرسالة