It's like I made the language myself, but it didn't work out the way I wanted it to.

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

void randd(int a[]) {

    int i;

    srand(time(NULL));
    for (i = 0; i < 5; i = i + 1) {
        a[i] = rand() % 10 + 1;
    }
}


    int main(void) {
        int bayeol[5];

        void randd(bayeol);

        printf("%d\n %d\n%d\n %d\n", bayeol[0], bayeol[1], bayeol[2],
            bayeol[3]);
    }

#include has been declared.

It represents a function that allocates up to 10 or less random variables to each element in the array There is no error, but there is no change when I execute it. I wonder what's wrong.

c

2022-09-20 15:13

1 Answers

void land(int *a) { << here
        int i;
        srand(time(NULL));
        for (i = 0; i < 5; i++) {
                a[i] = rand() % 10 + 1;
        }
}


int main(void) {
        int bayeol[5];
        rand(bayeol); <<< Here
        printf("%d\n %d\n%d\n %d\n", bayeol[0], bayeol[1], bayeol[2],bayeol[3]);
}

function call And you can use the global variable or the address value.


2022-09-20 15:13

If you have any answers or tips


© 2022 pinfo. All rights reserved.