clevernessisamyth

Info 2eme annee 2004 INPT

Aug 18th, 2020 (edited)
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. //Exercice 1:
  2. #include <stdio.h>
  3.  
  4. void main(void)
  5. {
  6.     int T[10];
  7.     int Emax = -1;
  8.  
  9.     for( int i=0 ; i<10 ; i++ )
  10.     {
  11.         printf("Element %d: ", i+1);
  12.         scanf("%d", &T[i]);
  13.         if(T[i] > Emax)
  14.             Emax = T[i];
  15.     }
  16.  
  17.     printf("Les indices de Emax = %d dans T sont: ", Emax);
  18.  
  19.     for( int i=0 ; i<10 ; i++ )
  20.     {
  21.         if(T[i] == Emax)
  22.             printf("%d, ", i+1);
  23.     }
  24.  
  25. }
  26.  
  27. //Exercice 2:
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <ctype.h> // toupper();
  31.  
  32. void main(void)
  33. {
  34.     char str[11];
  35.     size_t taille;
  36.     int i, j;
  37.  
  38.     do
  39.         {
  40.             printf("Enter une chaine de caractere de 10 caractere au maximum: ");
  41.             gets(str);
  42.             taille = strlen(str);
  43.             printf("Taille: %d\n", taille);
  44.         }
  45.     while(taille > 10);
  46.  
  47.     printf("La chaine %s", str);
  48.  
  49.     for( i=0, j=taille-1 ; i<j ; i++, j-- )
  50.     {
  51.         if( toupper(str[i]) != toupper(str[j]) )
  52.             break;
  53.     }
  54.  
  55.     if(i>=j)
  56.         printf(" est un Palindrome");
  57.     else
  58.         printf(" n'est pas un Palindrome");
  59.  
  60. }
Add Comment
Please, Sign In to add comment