Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

How to generate a random array in c

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

main(){
    int vet[1000], fre[50];
    int i;

    srand(time(NULL));

    for(i=0;i<1000;i++){
        vet[i]=(rand()%51);
    }

    for(i=0;i<1000;i++){
        printf("%d
", vet[i]);
    }

    for(i=0;i<1000;i++){
        fre[vet[i]]=fre[vet[i]]+1;
    }

    for(i=0;i<51;i++){
        printf("The number %d  was generated %d times
", i, fre[i]);
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #generate #random #array
ADD COMMENT
Topic
Name
3+3 =