Advertisement
luizaspan

Rand

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