0
#include <math.h>
#include <stdio.h>

float Fact(int x) {
    if (x == 1 || x == 0)
        return 1;
    else
        return x * Fact(x - 1);
}

int main() {
    float c;
    float d;
    float y;
    for(int n = 0; n < 10; n++) {
        c = 3 * (pow(n, n));
        y = Fact(n);
        d = y / c;
        printf("Result: %f", d);
    }
}
FAILED: untitled1 
: && /usr/bin/cc -g  CMakeFiles/untitled1.dir/main.c.o -o untitled1   && :
/usr/bin/ld: CMakeFiles/untitled1.dir/main.c.o: in function `main':
/home/unoiko/CLionProjects/untitled1/main.c:16: undefined reference to `pow'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Don't know where misstake

Andreas Wenzel
  • 22,760
  • 4
  • 24
  • 39
  • 1
    If you are using gcc, I believe that you must link with the math library in order to use functions from `math.h`, by adding the command line option `-lm` when invoking the compiler. – Andreas Wenzel Dec 17 '22 at 16:57
  • @AndreasWenzel sorry, I didn't understand exactly where to add lm? – Матвей Поляков Dec 17 '22 at 17:04
  • Are you invoking the compiler/linker yourself or is your [IDE](https://en.wikipedia.org/wiki/Integrated_development_environment) doing that for you? If you are using an IDE, then you will have to consult your IDE's documentation on how to add command-line arguments to the compiler/linker. – Andreas Wenzel Dec 17 '22 at 17:09
  • @AndreasWenzel yes, im install IDE - CLion, but i don't know how it working, i will try to search info at internet, thx for answer – Матвей Поляков Dec 17 '22 at 17:10
  • I found [this link](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206607085-CLion-Enabling-math-h-for-C-projects) which explains how to add the math library to your CLion project. I don't know if it is accurate, because I do not use CLion. – Andreas Wenzel Dec 17 '22 at 17:17

0 Answers0