Thread: square root

  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    7

    square root

    Hi
    I'm a newbie, I'm trying to understand c programing language. But I have an issue. Why do I get this error?
    rootsquer.c
    Code:
    #include <math.h>
    #include <stdio.h>
    
    int main() {
       double number, squareRoot;
    
       printf("Enter a number: ");
       scanf("%lf", &number);
    
       // computing the square root
       squareRoot = sqrt(number);
    
       printf("Square root of %.2lf =  %.2lf", number, squareRoot);
    
       return 0;
    }
    Code:
    $ clang -ansi rootsquer.c -o rootsquer   
    /usr/bin/ld: /tmp/rootsquer-fe5919.o: in function `main':
    rootsquer.c:(.text+0x41): undefined reference to `sqrt'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    150
    You need to link with the math library.
    Link in the Math Library | C For Dummies Blog

  3. #3
    Registered User
    Join Date
    Jan 2021
    Posts
    7

    [solved]

    Thank you. I appreciate it a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Square Root C
    By useredu in forum C Programming
    Replies: 10
    Last Post: 04-12-2014, 03:43 PM
  2. Square Root
    By Kyoto Oshiro in forum C++ Programming
    Replies: 5
    Last Post: 09-05-2002, 01:22 AM
  3. Square root
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 07-05-2002, 06:35 AM
  4. how do u get the square root
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 06-11-2002, 04:36 PM
  5. square root
    By help in forum C Programming
    Replies: 5
    Last Post: 08-29-2001, 05:46 AM

Tags for this Thread