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

Thanks all

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

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)

* 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

Powered by vBulletin® Version 4.2.2 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.