mardi 9 janvier 2018

Negative and Real random numbers

I want to ask if there is a way i can make a program in c print random numbers from -1 to 1 [-1,1].Also i want to know how can it generate random numbers that are not integers.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
    int N;
    printf("How many numbers you wish to print? : ");
    scanf("%d",&N);
    float arr[N];
    srand(time(NULL));
    for(int i=0; i<N; i++)
    {
        arr[i] = rand() % 2;
        printf("%f\n",arr[i]);
    }
}




Aucun commentaire:

Enregistrer un commentaire