c - Random number generation in sets of 2 -


this question has answer here:

i have made code generate random no in set of 2 coordinates (1.00,4.00), (3.00,6.00) want result in decimal (1.45,4.87),(3.56,6.45) digits after decimal code show zeros after decimal.

my code is

#include<stdio.h> #include<stdlib.h> #include<time.h>  int main () {     srand(time(null));     int a[100][2],i,j;     (i=0; i<100; i++) {         (j=0; j<2; j++) {             a[i][j]= rand()%11;         }     }     (i=0; i<100; i++) {         printf("(");         (j=0; j<2; j++) {             printf("%d",a[i][j]);             if(j==0)                 printf(",");         }         printf(") ");     }     scanf("%d");     return 0; } 

use double instead of int

// int a[100][2],i,j; double a[100][2]; int i, j; 

also write function generate floating point random numbers, rather integer random numbers

// generate numbers in interval [0, 1[ double randd_opened(void) {     return rand() / (rand_max + 1.0); }  // generate numbers in interval [0, 1] double randd_closed(void) {     return rand() / (double)rand_max; } 

note: multiplying random number in interval [0, 1] x gives random number in interval [0, x].


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -