How to use C’s Pow function?

Asked

Viewed 2,438 times

0

The program is not complete yet, but should at least run the 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 could not understand very well the error and, consequently, I could not find the place of error.

  • Luke, why are you undoing the issues? They are intended to make the question more legible.

  • I don’t mean to,!

  • You can help me in my mistake?

  • How are you compiling?

  • gcc filename. c -the filename.exe

1 answer

3


You need to pass the parameter -lm for gcc to enable the link to the mathematical library.

Stay like this:

gcc nome_do_arquivo.c -o nome_do_arquivo.exe -lm
  • obridago,I forgot I had put the library Math.vlw

Browser other questions tagged

You are not signed in. Login or sign up in order to post.