-5

While using sqrt (n) with any variable n I am getting an error undefined reference to sqrt.

  • Because you didn't include `-lm` on the link line after the object file name. On some systems, you have to specify `-lm` to link the maths library, which is where `sqrt()` is kept. Other systems do not need the separate maths library; the maths functions are in the main C library. – Jonathan Leffler Dec 13 '14 at 17:02
  • Did you include `#include ` ? – Rizier123 Dec 13 '14 at 17:02
  • 1
    Please, show the example. – nbro Dec 13 '14 at 17:02

1 Answers1

-1

You should use #include <math.h>. If you are using C++ use #include <cmath>.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278