mercredi 17 avril 2019

can someone please explain why this code doesn't work?

I'm making a random number generator that takes the number and takes another number from an array and prints the number from the array. I'm not sure how to get a random number. I haven't tried a lot because I'm new to c.

#include <stdio.h>

int main()
{
    int *comp_nums[]={"1", "2","4","6","12","24","36","48","60","120","180","240","360","720","840","1260","1680","2520","5040"};
    srand(time(NULL));
    int r = rand();
    int i;
    for (i=0; i <10;) {
        int n=rand(0,19);
        char *x=comp_nums[n];
        printf("%d", x);
        return 0;
    }
}

This is the code I've tried and doesn't print anything.




Aucun commentaire:

Enregistrer un commentaire