error in Pow() and sqrt()

Asked

Viewed 321 times

-1

I’m finding a mistake in this code, but it looks okay to me. Terminal error after trying to compile(gcc):

[in the function "main": Exercise-11.c:(.text+0x6e): undefined reference for "sqrt" /usr/bin/Ld: Exercise-11.c:(.text+0xd8): no reference set to "Pow" collect2: error: Ld returned 1 Exit status]

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

void main() {

    double number, raiz, quadrado;

    printf("Digite um número:\n");
    scanf("%lf", &number);

    if (number>0)
    {
        printf("O numero é maior que 0 então vou tirar a raiz quadrada\n");
        raiz = sqrt(number);
        printf("O resultado da raiz quadrada de %.0lf é %.0lf", number, raiz);

    } else if (number<0) {
        
        printf("O numero é menor que 0 então vou elevar ao quadrado\n");
        quadrado = pow(number, 2);
        printf("O resultado do quadrado de %.0lf é %.0lf", number, quadrado);
    }
    
    
    
}
  • 1

    Specify the -lm parameter in the build.

  • what do you mean? I couldn’t solve

  • If you are using gcc: gcc -o executavel fonte.c -lm

  • thanks, I didn’t know this parameter.

1 answer

0

So you can use the Math. h library or put it in the build(-1m) parameters of your IDE gcc -o </path/do/program/program. c> -1m

Browser other questions tagged

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