10

Series of random numbers

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. main() {
  6.     int min, max;
  7.     int i;
  8.  
  9.     printf("Enter min and max: ");
  10.  
  11.     if ( scanf("%d %d", &min, &max) == 2 ) {
  12.         int gap = max - min + 1;
  13.         srand( time(0) );
  14.         for ( i = 0; i < 20; ++i )
  15.             printf( "%d ", rand()/100 % gap + min);
  16.         printf("\n");
  17.     }
  18.  
  19.     exit(0);
  20. }
$ 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

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].