1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include<stdio.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
int fon(int *tab, int Nb)
{
int i,index;
for (i = 0; i < Nb; i++)
if (tab[i] == 0)
index = i;
return index;
}
int fonct(int *tab, int p, int Nb,int s)
{
int index,i,Nbo;
Nbo = 0;
i = 0;
while ((Nbo <= p) && (i < Nb))
{
if (tab[i] == 0)
Nbo = Nbo + 1;
i = i + 1;
if (s == (Nb - 1))
{
if (tab[i]==0)
index=i;
}
else if (tab[i] == 1)
index = fon(tab, Nb);
index = i - 1;
}
printf("index=%d\n", index);
return index;
}
int main(int argc, char *argv[])
{
int *ta;
int i,r,vic,s,Nb;
srand(time(NULL));
Nb = atoi(argv[1]);
ta = (int*)calloc(Nb, sizeof(int));
r = rand() % Nb;
printf("premiere vic=%d\n", r);
ta[r] = 1;
s = 0;
r = rand() % (Nb - 1);
printf("le r est :%d\n", r);
while (s != (Nb))
{
vic = fonct(ta, r, Nb, s);
if (vic == Nb)
ta[vic-1] = 1;
else
ta[vic] = 1;
for (i = 0; i < Nb; i++)
printf("ta[%d]=%d\n", i, ta[i]);
s = s + 1;
printf("%d\n", s);
r = rand() % (Nb - s);
printf("le r de la boucle est:%d\n", r);
}
return 0;
} |
Partager