how to generate a random array in c

Solutions on MaxInterview for how to generate a random array in c by the best coders in the world

showing results for - "how to generate a random array in c"
Giuseppe
06 Apr 2020
1#include <stdio.h>
2#include <stdlib.h>
3#include <time.h>
4
5main(){
6    int vet[1000], fre[50];
7    int i;
8
9    srand(time(NULL));
10
11    for(i=0;i<1000;i++){
12        vet[i]=(rand()%51);
13    }
14
15    for(i=0;i<1000;i++){
16        printf("%d\n", vet[i]);
17    }
18
19    for(i=0;i<1000;i++){
20        fre[vet[i]]=fre[vet[i]]+1;
21    }
22
23    for(i=0;i<51;i++){
24        printf("The number %d  was generated %d times\n", i, fre[i]);
25    }
26}
27
queries leading to this page
random array cc random arraygenerate a random array in cgenerate an array of random objects in chow to generate a random array in cgenerate array of random numbers cgenerate random matrix in crandom number in an array ccreate random array in cgenrate array in c randomhow to generate random array in cbuilding a random array cget a random element from an array crandom array in chow to store random numbers in an array cgenerate random no array in cgenerate random matrix creturn random element of an array c programmingc program to generate random numbers in arrayhow to generate random numbers in an array in crandomize array in chow to create an array and loop that generate randow numbers in cpicking randomly from an array carray randomize crandom integer array crandomize an array in crandom from array in cfunction to generate random matrix in cgenerate random array in crandomize array ccreate array of random numbers in crandom number array in cc array with random numbers inthow generate array of random numbers in crandom in array crandomize element of an array c programmingrandom array generator in cprogram to create random array numbers cc function random array generatorc randomizing arraypick a random in array cc random array elementgenerate random array of numbers crandom number to an array chow to generate an array of random numbers in cgen array of random numbers cget random number from array cc randomize arrayhowto print random from array in ctake random input in array in cc generate random numbers arrayc generate random arrayget random item from array chow to generate a random array in c