Jump to content

Problema com o sqrt


bsr
 Share

Recommended Posts

Tou a dar os meu primeiros passo com o C e tou a ter um erro esquesito por causa do sqrt, o programa em causa ´e o seguinte:

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

int main(){

   int a;
   int b;

   printf("Insira o valor de a:");
   scanf("%d",&a);

   b = sqrt (a);

   printf("O valor de b: %f\n",b);

   return 0;
}

E esta a dar-me o erro " undefined reference to `sqrt' ", ja me deu tambem ao usar a funcao pow.

O compilador que uso e o gcc.

Obrigado.

Link to comment
Share on other sites

Em C, se necessitas da biblioteca math.h, para além de incluires a biblioteca tens de compilar da seguinte forma:

gcc -lm programa.c -o programa

"What we do for ourselves dies with us. What we do for others and the world, remains and is immortal.", Albert Pine

Blog pessoal : contém alguns puzzles, algoritmos e problemas para se resolver com programação.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.