Search
 
SCRIPT & CODE EXAMPLE
 

C

Trier lexicographiquement en c

#include <stdio.h>
#include <string.h>
main()
{
 /* Déclarations */
 char MOT[10][50]; /* tableau de 10 mots à trier */
  char AIDE[50];  /* chaîne d'aide pour la permutation */
 int I;    /* rang à partir duquel MOT n'est pas trié */
 int J;    /* indice courant */
 int PMOT; /* indique la position du prochain mot */
           /* dans la suite lexicographique.        */

 /* Saisie des données */
 for (J=0; J<10; J++)
   {
    printf("Mot %d : ", J);
    gets(MOT[J]); /* ou :  scanf ("%s
", MOT[J]); */ 
    }

 /* Tri du tableau par sélection directe du     */
 /* prochain mot dans la suite lexicographique. */
 for (I=0; I<9; I++)
    {
     /* Recherche du prochain mot à droite de A[I] */
     PMOT=I;
     for (J=I+1; J<10; J++)
        if (strcmp(MOT[J], MOT[PMOT]) < 0)
            PMOT=J;
     /* Echange des mots à l'aide de strcpy */
     strcpy(AIDE, MOT[I]);
     strcpy(MOT[I], MOT[PMOT]);
     strcpy(MOT[PMOT], AIDE);
    }

 /* Edition du résultat */
 printf("Tableau trié lexicographiquement :
");
 for (J=0; J<10; J++)
     puts(MOT[J]);  /* ou :  printf("%s
",MOT[J]); */
 printf("
");
 return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: 50 north main 07522 
C :: type conversion 
C :: c ausgabe von variablen 
C :: how to import c data type 
C :: bullseye lxc network problem 
C :: shortest job first 
C :: C program determines the height status for heights in cm 
C :: deepak rake 
C :: change no_turbo 
C :: escaping characters in hibernate queries 
C :: buildCheckFunction(locations) 
C :: print number in c 
C :: np mean 2nd dimension 
C :: c input is skipped 
C :: how to get a string input in c 
C :: transpose of a matrix in c 
C :: what is implicit typecasting 
C :: crear funcion en c 
Dart :: how to diable flutter for web 
Dart :: rounded raisedbutton in flutter 
Dart :: flutter appbar text color 
Dart :: dart round to 2 decimals 
Dart :: how to print in the same line in dart 
Dart :: put container in bottom column flutter 
Dart :: How do you add a label (title text) to a Checkbox in Flutter? 
Dart :: dart card outline 
Dart :: dart map foreach 
Dart :: flutter iconbutton 
Dart :: flutter listtile disable 
Dart :: flutter main.dart 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =