[Solved] Why my function doesn’t work?


Your exponent function needs to return the n instead of x and in your main() you probably want to initialize the variable x to the value of function exponent with an argument of 5:

int x = exponent(5);

prior to printing via:

print_exponent(x);

That being said, your exponent function is broken as the return value is always the same no matter the parameter value. Modify the for loop to be:

for (int i = 1; i < x; i++) {
    n *= 6;
}

And you probably want to check if the parameter is equal to 0:

if (x == 0) {
    return 1;
}

3

solved Why my function doesn’t work?