How to use the pow function of C?

0

The program is not complete yet, but should at least run função1 . The following error is occurring:

/tmp/ccbRtCar.o: na função 'funcao1':
iniciosimulado02.c:(.text+0x18f): referência indefinida para 'pow'
collect2: error: ld returned 1 exit status

Follow the program:

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

int main() {
    int x = 1;
    imprimemenu();
    questao03(x);
    return (0);
}

int imprimemenu() {
    printf("\n(1)  funcao  1\n");
    printf("\n(2)  funcao  2\n");
    printf("\n(3)  funcao  3\n");
    printf("\n(0)  sair \n");
    return (0);
}

int questao03(int x) {
    int y;
    int z, a;
    while (x != 3) {
        printf("Escolha a opcao do menu: \n");
        scanf("%i", &x);
        switch (x) {
            case 1:
                printf("Digite o numeros do qual será extraída a raiz: \n");
                scanf("%i", &y);
                printf("Digite a ordem da raiz: \n");
                scanf("%i", &z);
                funcao1(y, z);
                printf("O resultado da conta deu: %i \n", a);
                break;
            case 2:
                printf("essa funcao nao retorna \n");
                break;
            case 3:
                printf("essa funcao nao retorna \n");
                break;
            default:
                printf("valores entre 0 e 3\n");
        }
    }
}

int funcao1(int y, int z) {
    int k;
    k = pow(y, 1 / z);
    return (k);
}

I did not understand the error very well and therefore did not find the location of the error.

    
asked by anonymous 14.10.2017 / 20:44

1 answer

3

You need to pass the -lm parameter to gcc to enable linking with the math library.

It looks like this:

gcc nome_do_arquivo.c -o nome_do_arquivo.exe -lm
    
14.10.2017 / 21:38