dimanche 2 janvier 2022

'rand()' gives weird numbers [closed]

I'm trying to code a void function that takes 50 random numbers between two parameters and assigns to an array for homework. And output gives me a bunch of 0 and weird numbers like 4254585 or 11277136, how can i fix that.

#include <time.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

void rndnums(int max ,int min, int arr[50])
{
    int rnd;

    srand(time(NULL));

    for(int i=0; i<50; i++)
    {
        rnd = rand() % max + min;
        arr[i] = rnd;
    }
}

int main()
{
    int arr[50];
    rndnums(30, 10, &arr[50]);

    for(int i=0; i < 50; i++)
        cout << i + 1 << ". = " << arr[i] << endl;
}



Aucun commentaire:

Enregistrer un commentaire