i've just upgraded my slackware box to 9.0 (from 8.1) and tried doing
this just to check my programming skills, as well as the new features of
the gcc compiler.

i get this error when i try compiling the source file which contains the
code snippet as follows.

<code>

#include <math.h>
                                                                                
int isprime(int n) {
        int prime=1; /* assume that the number is prime */
        int dlimit, dit;
                                                                                
        if (!(n % 2))   /* if divisible by 2 (or even) */
                prime = 0;      /* it's not prime */
        dlimit = (int) sqrt ( (double) n); /* result of sqrt is a double
*/
        for (dit = 3; (dit <= dlimit) && (prime); dit+=2)
                if (!(n % dit)) /* if divisible by odd numbers */
                        prime = 0; /* then it's not prime */
                                                                                
        return prime;
}

</code>

in the shell:

[EMAIL PROTECTED]:~/src/csrc$ gcc prime.c -o prime
/tmp/ccAwYhXb.o(.text+0x2c): In function `isprime':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status

what am i doing wrong here? any ideas? i'm bothered because i might get
the same errors when trying to develop applications later that would use
the gcc-3 compiler family.

TIA. =)

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to