Advertisement
luizaspan

Rand III

Jun 2nd, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h> // rand() ou random()
  3. #include <time.h>
  4.  
  5. #define n 100
  6.  
  7. int main(void)
  8. {
  9.   int i,a[n];
  10.   double x[100];
  11.  
  12.   // gerando nova sequencia de numeros aleatórios:
  13.   srand(time(0));
  14.      
  15.   for (i=0;i<100;i++)
  16.     {
  17.       x[i]=(double) rand()/RAND_MAX;
  18.       a[i]=rand()%n +1;
  19.       a[i]=(double) rand()/RAND_MAX*n;
  20.  
  21.       printf("%lf\t %d \n",x[i],a[i]);      
  22.     }
  23.      
  24.   // RAND_MAX definido no <stdlib.h>
  25.   // número aleatório entre 1 e RAND_MAX
  26.      
  27.   return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement