3
Série de nombres aléatoires
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- main() {
- int min, max;
- int i;
- printf("Enter min and max: ");
- if ( scanf("%d %d", &min, &max) == 2 ) {
- int gap = max - min + 1;
- srand( time(0) );
- for ( i = 0; i < 20; ++i )
- printf( "%d ", rand()/100 % gap + min);
- printf("\n");
- }
- exit(0);
- }
$ gcc -o rand rand.c
$ ./rand
Enter min and max: 0 10
4 8 9 2 5 2 10 7 1 5 4 2 5 10 9 8 0 8 1 9
$ ./rand
Enter min and max: -1 1
1 1 -1 0 0 1 0 -1 0 1 -1 0 -1 -1 1 1 0 0 -1 0
Commentaires