How to generate a random array in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
static const int SIZE = 10;

int main(void) {
    int arr[SIZE];

    srand(time(NULL));

    for (int i = 0; i < SIZE; i++) {
        arr[i] = (rand() % 100) + 1;
    } 

    for (int i = 0; i < SIZE; i++) {
        printf("%d ", arr[i]);
    } 
      
    return 0;
}
 
 
 
 
/*
run:
 
8 53 49 7 79 5 67 54 100 59 
 
*/

 



answered Mar 15, 2022 by avibootz
...