Salut,
Pour info, qu est ce que tu connais en C en gros ?
(tu as eu des cours sur quoi et tu developpes habituellement sous quel OS ?)
l ordre du tri c est croissant ?
[EDIT: ordre de tri]
[ Ce message a été modifié par : : MisaAmane le 07-12-2007 17:50 ]
Ajout du 07-12-2007 à 18:01:
Je me suis bien amuser ;)
Si tu veux des commentaires ou si tu ne comprends pas quelque chose dis moi.
[tester avec CygWin]
Code: 

- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- void afftab(int **tab, int k, int l)
- {
- for (int i = 0;i < k;i++)
- for (int j = 0;j < l;j++)
- printf("[%d][%d] >> [%d]\n",i,j,tab[i][j]);
- }
-
- void affsumtab(int **tab, int k, int l)
- {
- for (int i = 0;i < k;i++)
- printf("[%d] ",tab[i][l]);
- printf("\n");
- }
-
- void sum_line(int **tab, int i, int k, int l)
- {
- int sum = 0;
-
- for (int j = 0; j < l; j++)
- sum += tab[i][j];
- tab[i][k] = sum;
- }
-
- void permuttab(int **tab, int k, int j)
- {
- int *tmp;
- tmp = tab[k];
- tab[k] = tab[j];
- tab[j] = tmp;
- }
-
- void tritab(int **tab, int nblines, int nbrows)
- {
- int i,j,k,l;
-
- for (i = 0, k = 1;i < nblines && k;i++)
- {
- k = 0;
- for (j = 1;j < nblines - i;j++)
- {
- if (tab[j][nbrows] < tab[j - 1][nbrows])
- {
- permuttab(tab, j, j - 1);
- printf ("[%d] & [%d]\n", j, j - 1);
- k = 1;
- }
- }
- }
- }
-
- int **gentab(int nblines, int nbrows)
- {
- int **tab;
- int i,j;
-
- srand ((unsigned) time (NULL));
- rand();
- tab = (int **) malloc(nblines * sizeof(int *));
- for (i = 0;i < nblines;i++)
- {
- tab[i] = (int *) malloc((nbrows + 1) * sizeof(int));
- for (j = 0;j < nbrows;j++)
- tab[i][j] = (int) ((double)rand() / ((double)RAND_MAX + 1) * 6); // 0-5 => 6 chiffres
- sum_line(tab, i, j, nbrows);
- }
- return (tab);
- }
-
- int main(int ac, char **av)
- {
- int nbrows;
- int nblines;
- int **tab;
-
- if (ac != 3)
- {
- printf ("Usage: %s [nb colonnes] [nb lignes]\n", av[0]);
- return (-1);
- }
- nbrows = atoi(av[1]);
- nblines = atoi(av[2]);
- tab = gentab(nblines, nbrows);
-
- printf ("Tableau non trie\n");
- // afftab(tab, nblines, nbrows + 1);
- affsumtab(tab, nblines, nbrows);
-
- tritab(tab, nblines, nbrows);
-
- printf ("Tableau trie\n");
- // afftab(tab, nblines, nbrows + 1);
- affsumtab(tab, nblines, nbrows);
-
- return (1);
- }