Advertisement
paulogp

Números aleatórios

Jul 13th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. /* Este código permite gerar números aleatórios entre 1 e 10 */
  2. // Apple Xcode
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8.  
  9. int main (int argc, const char * argv[])
  10. {
  11.     // random numbers
  12.     int the_result = 0;
  13.  
  14.     // seed the random sequence generated by rand()
  15.     srand((unsigned)time(NULL));
  16.  
  17.     // 8 random numbers between 1 and 10
  18.     for (int i = 0; i < 8; i++)
  19.     {
  20.         the_result = (rand() % 10) + 1;
  21.         printf("%3d ", the_result);
  22.     }
  23.  
  24.     printf("\n");
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement