-2

Why won't this program run?

#include<stdio.h>
int main()
{
    printf("%f\n", log(36.0));
    return 0;
}
Mohit Jain
  • 30,259
  • 8
  • 73
  • 100

1 Answers1

4

You have to include

#include<math.h>

This is because math.h is a header file in the standard library of C programming language designed for basic mathematical operations.

  • 3
    And link the math library with `-lm` as a compiler option. – squiguy Mar 11 '15 at 05:03
  • 2
    @squiguy actually in this case both `gcc` and `clang` can [use builtin functions if the argument is a constant expression in many cases](http://stackoverflow.com/a/24294632/1708801) but in the general case you need to use `-lm`. – Shafik Yaghmour Mar 11 '15 at 13:09