PDA

View Full Version : How can I use math.h in C?



Lster
September 12th, 2006, 09:46 AM
Some code I have made gives me an error because it cant find sqrt and floor. I thought they were included in math.h. It works with g++, but I would prefer to use gcc.

Thanks all

amo-ej1
September 12th, 2006, 10:29 AM
* First you're missing a ; after your printf()
* Second:
when you read the manpage (man sqrt) you'll see



NAME
sqrt, sqrtf, sqrtl - square root function

SYNOPSIS
#include <math.h>

double sqrt(double x);
float sqrtf(float x);
long double sqrtl(long double x);

Link with -lm.


So your solution is



gcc -lm file.c


(oh and using [code] tags will preserve your identation)

Lster
September 12th, 2006, 10:46 AM
Wow... Thankyou soooo much :-D